From bd6d0f3fd56318da43f0ae75f0f0d5ebbf490cb6 Mon Sep 17 00:00:00 2001 From: zcourts Date: Mon, 15 Dec 2014 17:23:45 +0000 Subject: [PATCH] ensure getRawQuery is not null before appending Motivation: without this check then given a URI with path /path the resulting URL will be /path?null= Modifications: check that getRawQuery doesn't return null and only append if not Result: urls of the form /path will not have a null?= appended --- .../io/netty/handler/codec/http/QueryStringDecoder.java | 2 +- .../netty/handler/codec/http/QueryStringDecoderTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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;