diff --git a/addressbuilder/src/main/java/org/ocpsoft/urlbuilder/util/Decoder.java b/addressbuilder/src/main/java/org/ocpsoft/urlbuilder/util/Decoder.java index 7a8df64c8..e6118a740 100644 --- a/addressbuilder/src/main/java/org/ocpsoft/urlbuilder/util/Decoder.java +++ b/addressbuilder/src/main/java/org/ocpsoft/urlbuilder/util/Decoder.java @@ -17,19 +17,17 @@ public static String query(final CharSequence query) return decode(query, true); } - public static String decode(final CharSequence path, final boolean query) - { - + public static String decode(final CharSequence path, final boolean query) { StringBuilder decoded = new StringBuilder(); int length = path.length(); int pos = 0; while (pos < length) { - // '+' -> ' ' for query strings if (query && path.charAt(pos) == '+') { decoded.append(' '); pos++; + continue; } // percent-encoded values @@ -68,7 +66,6 @@ public static String decode(final CharSequence path, final boolean query) else { decoded.append('\uFFFD'); } - } // not escaped @@ -76,11 +73,7 @@ public static String decode(final CharSequence path, final boolean query) decoded.append(path.charAt(pos)); pos++; } - } - return decoded.toString(); - } - } diff --git a/addressbuilder/src/test/java/org/ocpsoft/urlbuilder/util/DecoderTest.java b/addressbuilder/src/test/java/org/ocpsoft/urlbuilder/util/DecoderTest.java index 969caa159..8bbf56a90 100644 --- a/addressbuilder/src/test/java/org/ocpsoft/urlbuilder/util/DecoderTest.java +++ b/addressbuilder/src/test/java/org/ocpsoft/urlbuilder/util/DecoderTest.java @@ -28,6 +28,14 @@ public void pathNotEncoded() assertEquals("/foobar", Decoder.path("/foobar")); } + @Test + public void queryEndingWithSpaceDecoding() + { + assertEquals("foo ", Decoder.decode("foo%20", true)); + assertEquals("foo ", Decoder.decode("foo ", true)); + assertEquals("foo ", Decoder.decode("foo+", true)); + } + @Test public void pathSpaceDecoding() {