Preserve original encoding of the URI path component if the URI is valid
This commit is contained in:
parent
6992339b6c
commit
94fc91dae2
|
@ -217,15 +217,18 @@ public class URIUtils {
|
|||
uribuilder.setFragment(null);
|
||||
}
|
||||
if (flags.contains(UriFlag.NORMALIZE)) {
|
||||
final List<String> pathSegments = new ArrayList<String>(uribuilder.getPathSegments());
|
||||
final List<String> originalPathSegments = uribuilder.getPathSegments();
|
||||
final List<String> pathSegments = new ArrayList<String>(originalPathSegments);
|
||||
for (final Iterator<String> it = pathSegments.iterator(); it.hasNext(); ) {
|
||||
final String pathSegment = it.next();
|
||||
if (pathSegment.isEmpty() && it.hasNext()) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
if (pathSegments.size() != originalPathSegments.size()) {
|
||||
uribuilder.setPathSegments(pathSegments);
|
||||
}
|
||||
}
|
||||
if (uribuilder.isPathEmpty()) {
|
||||
uribuilder.setPathSegments("");
|
||||
}
|
||||
|
|
|
@ -82,6 +82,8 @@ public class TestURIUtils {
|
|||
Assert.assertEquals("http://thishost/Fragment_identifier%23Examples",
|
||||
URIUtils.rewriteURI(
|
||||
URI.create("http://thishost/Fragment_identifier%23Examples")).toString());
|
||||
Assert.assertEquals("http://thathost/foo%3Abar", URIUtils.rewriteURI(
|
||||
URI.create("http://thishost/foo%3Abar"), target).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue