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/21 15:54:10 UTC

[httpcomponents-client] branch HTTPCLIENT-1968 created (now b3b526c)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a change to branch HTTPCLIENT-1968
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.


      at b3b526c  HTTPCLIENT-1968: Preserve escaped PATHSAFE characters when normalizing URI path segments (backport from 4.5.x)

This branch includes the following new commits:

     new b3b526c  HTTPCLIENT-1968: Preserve escaped PATHSAFE characters when normalizing URI path segments (backport from 4.5.x)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[httpcomponents-client] 01/01: HTTPCLIENT-1968: Preserve escaped PATHSAFE characters when normalizing URI path segments (backport from 4.5.x)

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch HTTPCLIENT-1968
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit b3b526cef5b959e7f21f1c7805af434c9d38b55b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Jun 21 17:35:55 2019 +0200

    HTTPCLIENT-1968: Preserve escaped PATHSAFE characters when normalizing URI path segments (backport from 4.5.x)
---
 .../org/apache/hc/client5/http/utils/URIUtils.java | 27 +++++++++++-----------
 .../apache/hc/client5/http/utils/TestURIUtils.java |  2 ++
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
index ad8cac1..b8688e2 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/utils/URIUtils.java
@@ -28,6 +28,8 @@ package org.apache.hc.client5.http.utils;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Stack;
@@ -83,20 +85,19 @@ public class URIUtils {
         if (dropFragment) {
             uribuilder.setFragment(null);
         }
-        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 == '/';
+        final List<String> originalPathSegments = uribuilder.getPathSegments();
+        final List<String> pathSegments = new ArrayList<>(originalPathSegments);
+        for (final Iterator<String> it = pathSegments.iterator(); it.hasNext(); ) {
+            final String pathSegment = it.next();
+            if (pathSegment.isEmpty() && it.hasNext()) {
+                it.remove();
             }
-            uribuilder.setPath(buf.toString());
+        }
+        if (pathSegments.size() != originalPathSegments.size()) {
+            uribuilder.setPathSegments(pathSegments);
+        }
+        if (pathSegments.isEmpty()) {
+            uribuilder.setPathSegments("");
         }
         return uribuilder.build();
     }
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
index 7b0e08d..e2d0340 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/utils/TestURIUtils.java
@@ -78,6 +78,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