mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 04:22:16 +00:00
[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
This commit is contained in:
1 parent
f2d1417e4d
commit
5491cb256a
1 file changed
+18
-4
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user