diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 33b31bcd3f..ab2f1113e0 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -678,7 +678,7 @@ public class Util { for (int i = 0; i < s.length(); i++) { int c = s.charAt(i); - if (c<128 && c!=' ') { + if (c<128 && (c!=' ' && c!='&')) { out.append((char) c); } else { // 1 char -> UTF8 diff --git a/core/src/test/java/hudson/UtilTest.java b/core/src/test/java/hudson/UtilTest.java index 6ccd383c14..d912ab3d74 100644 --- a/core/src/test/java/hudson/UtilTest.java +++ b/core/src/test/java/hudson/UtilTest.java @@ -121,6 +121,15 @@ public class UtilTest extends TestCase { assertEquals(encoded, "http://hudson/job/Hudson%20Job"); } + /** + * Test that Strings that contain ampersand are correctly URL encoded. + */ + 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. */ @@ -128,7 +137,7 @@ public class UtilTest extends TestCase { 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",