diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java index 9ae6809e5b..35fafa635f 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/QueryStringDecoder.java @@ -159,7 +159,7 @@ public class QueryStringDecoder { hasPath = false; } // Also take care of cut of things like "http://localhost" - this.uri = rawPath + '?' + uri.getRawQuery(); + this.uri = rawPath + (uri.getRawQuery() == null? "" : '?' + uri.getRawQuery()); this.charset = charset; this.maxParams = maxParams; 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 341d870d18..49b069f6db 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 @@ -20,6 +20,7 @@ import org.junit.Assert; import org.junit.Test; import java.net.URI; +import java.net.URISyntaxException; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -27,6 +28,12 @@ import java.util.Map.Entry; public class QueryStringDecoderTest { + @Test + public void testBasicUris() throws URISyntaxException { + QueryStringDecoder d = new QueryStringDecoder(new URI("http://localhost/path")); + Assert.assertEquals(0, d.parameters().size()); + } + @Test public void testBasic() throws Exception { QueryStringDecoder d;