HTTPCLIENT-1960: URIBuilder incorrect handling of multiple leading slashes in path component
This commit is contained in:
parent
7824d98d0c
commit
123bd993cf
|
@ -83,8 +83,20 @@ public class URIUtils {
|
|||
if (dropFragment) {
|
||||
uribuilder.setFragment(null);
|
||||
}
|
||||
if (TextUtils.isEmpty(uribuilder.getPath())) {
|
||||
final String path = uribuilder.getPath();
|
||||
if (TextUtils.isEmpty(path)) {
|
||||
uribuilder.setPath("/");
|
||||
} else {
|
||||
final StringBuilder buf = new StringBuilder(path.length());
|
||||
boolean foundSlash = false;
|
||||
for (int i = 0; i < path.length(); i++) {
|
||||
final char ch = path.charAt(i);
|
||||
if (ch != '/' || !foundSlash) {
|
||||
buf.append(ch);
|
||||
}
|
||||
foundSlash = ch == '/';
|
||||
}
|
||||
uribuilder.setPath(buf.toString());
|
||||
}
|
||||
return uribuilder.build();
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public class TestURIUtils {
|
|||
URI.create("http://thishost/stuff"), null).toString());
|
||||
Assert.assertEquals("/", URIUtils.rewriteURI(
|
||||
URI.create("http://thishost//"), null).toString());
|
||||
Assert.assertEquals("/stuff///morestuff", URIUtils.rewriteURI(
|
||||
URI.create("http://thishost//stuff///morestuff"), null).toString());
|
||||
Assert.assertEquals("/stuff/morestuff", URIUtils.rewriteURI(
|
||||
URI.create("http://thishost//stuff/morestuff"), null).toString());
|
||||
Assert.assertEquals("http://thathost/stuff", URIUtils.rewriteURI(
|
||||
URI.create("http://thishost/stuff#crap"), target, true).toString());
|
||||
Assert.assertEquals("http://thathost/stuff#crap", URIUtils.rewriteURI(
|
||||
|
|
Loading…
Reference in New Issue