diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index d2bd7f3776..1140b1e8c7 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -703,7 +703,7 @@ public class Util { for (int i = 0; i < s.length(); i++) { int c = s.charAt(i); - if (c<128 && (c!=' ' && c!='&')) { + if (c<128 && c!=' ') { out.append((char) c); } else { // 1 char -> UTF8 @@ -728,8 +728,8 @@ public class Util { private static final boolean[] uriMap = new boolean[123]; static { String raw = - "! $ '()*+,-. 0123456789 = @ABCDEFGHIJKLMNOPQRSTUVWXYZ _ abcdefghijklmnopqrstuvwxyz"; - // "# %& / :;< >? [\]^ ` {|}~ + "! $ &'()*+,-. 0123456789 = @ABCDEFGHIJKLMNOPQRSTUVWXYZ _ abcdefghijklmnopqrstuvwxyz"; + // "# % / :;< >? [\]^ ` {|}~ // ^--so these are encoded int i; // Encode control chars and space @@ -744,11 +744,9 @@ public class Util { * 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. - * Also escapes & for convenience. - * (so alphanumeric and !@$*()-_=+',. are not encoded) + * (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. - * Do not use this method for encoding query parameters. * Method name inspired by PHP's rawurlencode. */ public static String rawEncode(String s) { diff --git a/core/src/test/java/hudson/UtilTest.java b/core/src/test/java/hudson/UtilTest.java index 4b5d25ed94..dc1904cb5e 100644 --- a/core/src/test/java/hudson/UtilTest.java +++ b/core/src/test/java/hudson/UtilTest.java @@ -122,17 +122,7 @@ public class UtilTest { String encoded = Util.encode(urlWithSpaces); assertEquals(encoded, "http://hudson/job/Hudson%20Job"); } - - /** - * Test that Strings that contain ampersand are correctly URL encoded. - */ - @Test - public void testEncodeAmpersand() { - final String urlWithAmpersand = "http://hudson/job/Hudson-job/label1&&label2"; - String encoded = Util.encode(urlWithAmpersand); - assertEquals(encoded, "http://hudson/job/Hudson-job/label1%26%26label2"); - } - + /** * Test the rawEncode() method. */ @@ -141,7 +131,7 @@ public class UtilTest { String[] data = { // Alternating raw,encoded "abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", - "01234567890!@$*()-_=+',.", "01234567890!@$*()-_=+',.", + "01234567890!@$&*()-_=+',.", "01234567890!@$&*()-_=+',.", " \"#%/:;<>?", "%20%22%23%25%2F%3A%3B%3C%3E%3F", "[\\]^`{|}~", "%5B%5C%5D%5E%60%7B%7C%7D%7E", "d\u00E9velopp\u00E9s", "d%C3%A9velopp%C3%A9s",