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:
Oleg Kalnichevski 2017-01-21 14:43:44 +00:00
parent 6e4759800f
commit 0554271750
2 changed files with 11 additions and 1 deletions

View File

@ -493,7 +493,7 @@ public class URIBuilder {
private static String normalizePath(final String path) {
String s = path;
if (s == null) {
return null;
return "/";
}
int n = 0;
for (; n < s.length(); n++) {
@ -504,6 +504,9 @@ public class URIBuilder {
if (n > 1) {
s = s.substring(n - 1);
}
if (!s.startsWith("/")) {
s = "/" + s;
}
return s;
}

View File

@ -292,4 +292,11 @@ public class TestURIBuilder {
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());
}
}