HTTPCLIENT-1803: Improved handling of malformed paths by URIBuilder
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1779735 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6e4759800f
commit
0554271750
|
@ -493,7 +493,7 @@ public class URIBuilder {
|
||||||
private static String normalizePath(final String path) {
|
private static String normalizePath(final String path) {
|
||||||
String s = path;
|
String s = path;
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
return null;
|
return "/";
|
||||||
}
|
}
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (; n < s.length(); n++) {
|
for (; n < s.length(); n++) {
|
||||||
|
@ -504,6 +504,9 @@ public class URIBuilder {
|
||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
s = s.substring(n - 1);
|
s = s.substring(n - 1);
|
||||||
}
|
}
|
||||||
|
if (!s.startsWith("/")) {
|
||||||
|
s = "/" + s;
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -292,4 +292,11 @@ public class TestURIBuilder {
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMalformedPath() throws Exception {
|
||||||
|
final String path = "@notexample.com/mypath";
|
||||||
|
final URI uri = new URIBuilder(path).setHost("example.com").build();
|
||||||
|
Assert.assertEquals("example.com", uri.getHost());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue