Skip to content

Commit 4c3d9e8

Browse files
silvafabiochkal
authored andcommitted
Fixed handling of spaces at the end of query strings (ocpsoft#259)
1 parent b779516 commit 4c3d9e8

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎addressbuilder/src/main/java/org/ocpsoft/urlbuilder/util/Decoder.java‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ public static String query(final CharSequence query)
1717
return decode(query, true);
1818
}
1919

20-
public static String decode(final CharSequence path, final boolean query)
21-
{
22-
20+
public static String decode(final CharSequence path, final boolean query) {
2321
StringBuilder decoded = new StringBuilder();
2422
int length = path.length();
2523
int pos = 0;
2624

2725
while (pos < length) {
28-
2926
// '+' -> ' ' for query strings
3027
if (query && path.charAt(pos) == '+') {
3128
decoded.append(' ');
3229
pos++;
30+
continue;
3331
}
3432

3533
// percent-encoded values
@@ -68,19 +66,14 @@ public static String decode(final CharSequence path, final boolean query)
6866
else {
6967
decoded.append('\uFFFD');
7068
}
71-
7269
}
7370

7471
// not escaped
7572
else {
7673
decoded.append(path.charAt(pos));
7774
pos++;
7875
}
79-
8076
}
81-
8277
return decoded.toString();
83-
8478
}
85-
8679
}

‎addressbuilder/src/test/java/org/ocpsoft/urlbuilder/util/DecoderTest.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public void pathNotEncoded()
2828
assertEquals("/foobar", Decoder.path("/foobar"));
2929
}
3030

31+
@Test
32+
public void queryEndingWithSpaceDecoding()
33+
{
34+
assertEquals("foo ", Decoder.decode("foo%20", true));
35+
assertEquals("foo ", Decoder.decode("foo ", true));
36+
assertEquals("foo ", Decoder.decode("foo+", true));
37+
}
38+
3139
@Test
3240
public void pathSpaceDecoding()
3341
{

0 commit comments

Comments
 (0)