提交 5491cb25 编写于 作者: M mindless

[Util.rawEncode] Change complicated if expression to simpler array lookup


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21537 71c3de6d-444a-0410-be80-ed276b4c234a
上级 f2d1417e
......@@ -652,11 +652,26 @@ public class Util {
}
}
private static final boolean[] uriMap = new boolean[123];
static {
String raw =
"! $ &'()*+,-. 0123456789 = @ABCDEFGHIJKLMNOPQRSTUVWXYZ _ abcdefghijklmnopqrstuvwxyz";
// "# % / :;< >? [\]^ ` {|}~
// ^--so these are encoded
int i;
// Encode control chars and space
for (i = 0; i < 33; i++) uriMap[i] = true;
for (int j = 0; j < raw.length(); i++, j++)
uriMap[i] = (raw.charAt(j) == ' ');
// If we add encodeQuery() just add a 2nd map to encode &+=
// queryMap[38] = queryMap[43] = queryMap[61] = true;
}
/**
* Encode a single path component for use in an HTTP URL.
* Escapes all non-ASCII, general unsafe (space and "#%<>[\]^`{|}~)
* and HTTP special characters (/;:?) as specified in RFC1738,
* plus backslash (Windows path separator).
* and HTTP special characters (/;:?) as specified in RFC1738.
* (so alphanumeric and !@$&*()-_=+',. are not encoded)
* Note that slash(/) is encoded, so the given string should be a
* single path component used in constructing a URL.
* Method name inspired by PHP's rawurlencode.
......@@ -669,8 +684,7 @@ public class Util {
char c;
for (int i = 0, m = s.length(); i < m; i++) {
c = s.charAt(i);
if ((c<64 || c>90) && (c<97 || c>122) && (c<38 || c>57 || c==47)
&& c!=61 && c!=36 && c!=33 && c!=95) {
if (c > 122 || uriMap[c]) {
if (!escaped) {
out = new StringBuilder(i + (m - i) * 3);
out.append(s.substring(0, i));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册