Skip to content

Commit

Permalink
bug: fix the plus decoding in ArmeriaHttpUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
yzfeng2020 committed Sep 30, 2024
1 parent ce8a5ef commit d0147cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private static String simpleConcat(String prefix, String path) {
* Decodes a percent-encoded path string.
*/
public static String decodePath(String path) {
if (path.indexOf('%') < 0) {
if (path.indexOf('%') < 0 && path.indexOf('+') < 0) {
// No need to decode because it's not percent-encoded
return path;
}
Expand Down Expand Up @@ -407,6 +407,11 @@ private static String slowDecodePath(String path, boolean decodeSlash) {
int dstLen = 0;
for (int i = 0; i < len; i++) {
final char ch = path.charAt(i);
if (ch == '+') {
buf[dstLen++] = (byte) ' ';
continue;
}

if (ch != '%') {
buf[dstLen++] = (byte) ((ch & 0xFF80) == 0 ? ch : 0xFF);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ void testDecodePath(boolean isPathParam) throws Exception {
} else {
assertThat(decodeFunc.apply("/%2F")).isEqualTo("/%2F");
}

// Tests for '+' decoding into ' '
assertThat(decodeFunc.apply("/foo+bar")).isEqualTo("/foo bar"); // '+' should be decoded into space
assertThat(decodeFunc.apply("/foo+%20bar")).isEqualTo("/foo bar"); // '+' and '%20' both decoded to space
assertThat(decodeFunc.apply("/foo+bar+baz")).isEqualTo("/foo bar baz"); // multiple '+' should be decoded to space
assertThat(decodeFunc.apply("/foo%20bar+baz")).isEqualTo("/foo bar baz"); // combination of '%20' and '+'
}

@Test
Expand Down

0 comments on commit d0147cc

Please sign in to comment.