Correctly decode URI in QueryStringDecoder. See #189
This commit is contained in:
parent
26871d2d05
commit
c12717bfed
@ -163,11 +163,21 @@ public class QueryStringDecoder {
|
||||
"maxParams: " + maxParams + " (expected: a positive integer)");
|
||||
}
|
||||
|
||||
String rawPath = uri.getRawPath();
|
||||
if (rawPath != null) {
|
||||
hasPath = true;
|
||||
} else {
|
||||
rawPath ="";
|
||||
hasPath = false;
|
||||
}
|
||||
// Also take care of cut of things like "http://localhost"
|
||||
String newUri = rawPath + "?" + uri.getRawQuery();
|
||||
|
||||
// http://en.wikipedia.org/wiki/Query_string
|
||||
this.uri = uri.toASCIIString().replace(';', '&');
|
||||
this.uri = newUri.replace(';', '&');
|
||||
this.charset = charset;
|
||||
this.maxParams = maxParams;
|
||||
hasPath = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,8 +15,11 @@
|
||||
*/
|
||||
package org.jboss.netty.handler.codec.http;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jboss.netty.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
@ -164,4 +167,91 @@ public class QueryStringDecoderTest {
|
||||
Assert.assertEquals(ed.getPath(), ad.getPath());
|
||||
Assert.assertEquals(ed.getParameters(), ad.getParameters());
|
||||
}
|
||||
|
||||
// See #189
|
||||
@Test
|
||||
public void testURI() {
|
||||
URI uri = URI.create("http://localhost:8080/foo?param1=value1¶m2=value2¶m3=value3");
|
||||
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||
Assert.assertEquals("/foo", decoder.getPath());
|
||||
Map<String, List<String>> params = decoder.getParameters();
|
||||
Assert.assertEquals(3, params.size());
|
||||
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||
|
||||
Entry<String, List<String>> entry = entries.next();
|
||||
Assert.assertEquals("param1", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value1", entry.getValue().get(0));
|
||||
|
||||
|
||||
entry = entries.next();
|
||||
Assert.assertEquals("param2", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value2", entry.getValue().get(0));
|
||||
|
||||
entry = entries.next();
|
||||
Assert.assertEquals("param3", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value3", entry.getValue().get(0));
|
||||
|
||||
Assert.assertFalse(entries.hasNext());
|
||||
}
|
||||
|
||||
// See #189
|
||||
@Test
|
||||
public void testURISlashPath() {
|
||||
URI uri = URI.create("http://localhost:8080/?param1=value1¶m2=value2¶m3=value3");
|
||||
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||
Assert.assertEquals("/", decoder.getPath());
|
||||
Map<String, List<String>> params = decoder.getParameters();
|
||||
Assert.assertEquals(3, params.size());
|
||||
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||
|
||||
Entry<String, List<String>> entry = entries.next();
|
||||
Assert.assertEquals("param1", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value1", entry.getValue().get(0));
|
||||
|
||||
|
||||
entry = entries.next();
|
||||
Assert.assertEquals("param2", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value2", entry.getValue().get(0));
|
||||
|
||||
entry = entries.next();
|
||||
Assert.assertEquals("param3", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value3", entry.getValue().get(0));
|
||||
|
||||
Assert.assertFalse(entries.hasNext());
|
||||
}
|
||||
|
||||
// See #189
|
||||
@Test
|
||||
public void testURINoPath() {
|
||||
URI uri = URI.create("http://localhost:8080?param1=value1¶m2=value2¶m3=value3");
|
||||
QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||
Assert.assertEquals("", decoder.getPath());
|
||||
Map<String, List<String>> params = decoder.getParameters();
|
||||
Assert.assertEquals(3, params.size());
|
||||
Iterator<Entry<String, List<String>>> entries = params.entrySet().iterator();
|
||||
|
||||
Entry<String, List<String>> entry = entries.next();
|
||||
Assert.assertEquals("param1", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value1", entry.getValue().get(0));
|
||||
|
||||
|
||||
entry = entries.next();
|
||||
Assert.assertEquals("param2", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value2", entry.getValue().get(0));
|
||||
|
||||
entry = entries.next();
|
||||
Assert.assertEquals("param3", entry.getKey());
|
||||
Assert.assertEquals(1, entry.getValue().size());
|
||||
Assert.assertEquals("value3", entry.getValue().get(0));
|
||||
|
||||
Assert.assertFalse(entries.hasNext());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user