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/04/24 07:47:10 UTC

[httpcomponents-client] branch 4.5.x updated: Fix bug in URIBuilder#isPathEmpty method to verify if encodedPath is an empty string

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

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


The following commit(s) were added to refs/heads/4.5.x by this push:
     new 8f6df72  Fix bug in URIBuilder#isPathEmpty method to verify if encodedPath is an empty string
     new e605ca0  Merge pull request #146 from varunnvs92/4.5.x
8f6df72 is described below

commit 8f6df7259a6ba6ea1516d0b92822df58f3c3831e
Author: Varun Nandi <va...@amazon.com>
AuthorDate: Tue Apr 23 16:35:15 2019 -0700

    Fix bug in URIBuilder#isPathEmpty method to verify if encodedPath is an empty string
---
 .../main/java/org/apache/http/client/utils/URIBuilder.java   |  4 ++--
 .../test/java/org/apache/http/client/utils/TestURIUtils.java | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java b/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
index bc7b2cb..b95ae4c 100644
--- a/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
+++ b/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
@@ -34,7 +34,6 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-
 import org.apache.http.Consts;
 import org.apache.http.NameValuePair;
 import org.apache.http.conn.util.InetAddressUtils;
@@ -521,7 +520,8 @@ public class URIBuilder {
      * @since 4.5.8
      */
     public boolean isPathEmpty() {
-        return (this.pathSegments == null || this.pathSegments.isEmpty()) && this.encodedPath == null;
+        return (this.pathSegments == null || this.pathSegments.isEmpty()) &&
+               (this.encodedPath == null || this.encodedPath.isEmpty());
     }
 
     /**
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 1e2b96e..4c81ef2 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
@@ -34,6 +34,7 @@ import org.apache.http.conn.routing.HttpRoute;
 import org.junit.Assert;
 import org.junit.Test;
 
+import static org.apache.http.client.utils.URIUtils.DROP_FRAGMENT;
 import static org.apache.http.client.utils.URIUtils.DROP_FRAGMENT_AND_NORMALIZE;
 import static org.apache.http.client.utils.URIUtils.NORMALIZE;
 
@@ -84,6 +85,17 @@ public class TestURIUtils {
     }
 
     @Test
+    public void testRewriteWithEmptyPath() throws Exception {
+        final HttpHost target = new HttpHost("thathost", -1);
+
+        Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
+            URI.create("http://thathost"), target, DROP_FRAGMENT_AND_NORMALIZE).toString());
+        Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
+            URI.create("http://thathost"), target, DROP_FRAGMENT).toString());
+    }
+
+
+    @Test
     public void testRewritePort() throws Exception {
         HttpHost target = new HttpHost("thathost", 8080); // port should be copied
         Assert.assertEquals("http://thathost:8080/stuff", URIUtils.rewriteURI(