You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/06/18 14:59:55 UTC
[httpcomponents-client] 01/01: Preserve original encoding of the
URI path component if the URI is valid
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch uri-rewrite-improvements
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 94fc91dae266754056585bb847a026454d7da014
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Jun 18 16:59:37 2019 +0200
Preserve original encoding of the URI path component if the URI is valid
---
.../src/main/java/org/apache/http/client/utils/URIUtils.java | 7 +++++--
.../src/test/java/org/apache/http/client/utils/TestURIUtils.java | 2 ++
2 files changed, 7 insertions(+), 2 deletions(-)
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 6a6a742..8eb7667 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<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();
}
}
- 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 4c81ef2..1899666 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