Skip to content

Commit

Permalink
HTTPCLIENT-1803: Improved handling of malformed paths by URIBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Jan 21, 2017
1 parent 6e47598 commit 0554271
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public String toString() {
private static String normalizePath(final String path) {
String s = path;
if (s == null) {
return null;
return "/";
}
int n = 0;
for (; n < s.length(); n++) {
Expand All @@ -504,6 +504,9 @@ private static String normalizePath(final String path) {
if (n > 1) {
s = s.substring(n - 1);
}
if (!s.startsWith("/")) {
s = "/" + s;
}
return s;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,11 @@ private List<NameValuePair> createParameters() {
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());
}

}

0 comments on commit 0554271

Please sign in to comment.