diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringEncoder.java index 504b6746c9..2fca889a07 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringEncoder.java @@ -238,13 +238,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. *
- * 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 == '~'; } } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java index 24324cd8c7..b6adc4e2ff 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringDecoderTest.java @@ -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 diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java index 5c93758ad3..e30459a06b 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/QueryStringEncoderTest.java @@ -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