Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
silvafabio committed Jan 28, 2018
1 parent b779516 commit c375d45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,19 +66,14 @@ public static String decode(final CharSequence path, final boolean query)
else {
decoded.append('\uFFFD');
}

}

// not escaped
else {
decoded.append(path.charAt(pos));
pos++;
}

}

return decoded.toString();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit c375d45

Please sign in to comment.