Fix QueryStringEncoder encodes tilde (#11590)
Motivation: In this issue(#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 #11578
This commit is contained in:
parent
445f747ce3
commit
3fc44b0a8e
@ -240,13 +240,13 @@ public class QueryStringEncoder {
|
||||
* 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 == '~';
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,9 @@ public class QueryStringDecoderTest {
|
||||
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
|
||||
|
@ -56,6 +56,11 @@ public class QueryStringEncoderTest {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user