diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java index 6a6a742a2..8eb7667e3 100644 --- a/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java +++ b/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java @@ -217,14 +217,17 @@ public class URIUtils { uribuilder.setFragment(null); } if (flags.contains(UriFlag.NORMALIZE)) { - final List pathSegments = new ArrayList(uribuilder.getPathSegments()); + final List originalPathSegments = uribuilder.getPathSegments(); + final List pathSegments = new ArrayList(originalPathSegments); for (final Iterator it = pathSegments.iterator(); it.hasNext(); ) { final String pathSegment = it.next(); if (pathSegment.isEmpty() && it.hasNext()) { it.remove(); } } - uribuilder.setPathSegments(pathSegments); + if (pathSegments.size() != originalPathSegments.size()) { + uribuilder.setPathSegments(pathSegments); + } } if (uribuilder.isPathEmpty()) { uribuilder.setPathSegments(""); diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java index 4c81ef23e..189966635 100644 --- a/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java +++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java @@ -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