Skip to content

Commit

Permalink
Fix QueryStringEncoder encodes tilde (netty#11590)
Browse files Browse the repository at this point in the history
Motivation:

In this issue(netty#11578 ) discussed that tilde should not be encoded in QueryStringEncoder, this pr is to fix this problem

Modification:

Modified QueryStringEncoder so that it does not encode tilde, and added a test case

Result:

Fixes netty#11578
  • Loading branch information
skyguard1 authored Aug 26, 2021
1 parent 6a7cccd commit 88fcb51
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ private static char forDigit(int digit) {
* unreserved characters do not need to be encoded, and include uppercase and lowercase
* letters, decimal digits, hyphen, period, underscore, and tilde.
* <p>
* unreserved = ALPHA / DIGIT / "-" / "_" / "." / "*"
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" / "*"
*
* @param ch the char to be judged whether it need to be encode
* @return true or false
*/
private static boolean dontNeedEncoding(char ch) {
return ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9'
|| ch == '-' || ch == '_' || ch == '.' || ch == '*';
|| ch == '-' || ch == '_' || ch == '.' || ch == '*' || ch == '~';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public void testBasic() {
assertEquals(2, d.parameters().get("abc").size());
assertEquals("1 23", d.parameters().get("abc").get(0));
assertEquals("124 ", d.parameters().get("abc").get(1));

d = new QueryStringDecoder("/foo?abc=%7E");
assertEquals("~", d.parameters().get("abc").get(0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public void testDefaultEncoding() throws Exception {
e.addParam("d", null);
assertEquals("/foo?a=1&b=&c&d", e.toString());
assertEquals(new URI("/foo?a=1&b=&c&d"), e.toUri());

e = new QueryStringEncoder("/foo");
e.addParam("test", "a~b");
assertEquals("/foo?test=a~b", e.toString());
assertEquals(new URI("/foo?test=a~b"), e.toUri());
}

@Test
Expand Down

0 comments on commit 88fcb51

Please sign in to comment.