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
This commit is contained in:
zcourts 2014-12-15 17:23:45 +00:00 committed by Norman Maurer
parent 8d4a97e05b
commit bd6d0f3fd5
2 changed files with 8 additions and 1 deletions

View File

@ -159,7 +159,7 @@ public class QueryStringDecoder {
hasPath = false; hasPath = false;
} }
// Also take care of cut of things like "http://localhost" // 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.charset = charset;
this.maxParams = maxParams; this.maxParams = maxParams;

View File

@ -20,6 +20,7 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -27,6 +28,12 @@ import java.util.Map.Entry;
public class QueryStringDecoderTest { 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 @Test
public void testBasic() throws Exception { public void testBasic() throws Exception {
QueryStringDecoder d; QueryStringDecoder d;