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 2017/10/25 14:57:45 UTC

httpcomponents-client git commit: HTTPCLIENT-1876. Improve the buildString() method in URIBuilder.

Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.5.x 1383e1f78 -> 2e303b854


HTTPCLIENT-1876. Improve the buildString() method in URIBuilder.


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/2e303b85
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/2e303b85
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/2e303b85

Branch: refs/heads/4.5.x
Commit: 2e303b854f88b67d98820bdd9cfdeac01f0ee54e
Parents: 1383e1f
Author: aleh_struneuski <al...@epam.com>
Authored: Wed Oct 25 11:02:42 2017 +0300
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Oct 25 11:43:12 2017 +0200

----------------------------------------------------------------------
 .../org/apache/http/client/utils/URIBuilder.java   |  2 +-
 .../apache/http/client/utils/TestURIBuilder.java   | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/2e303b85/httpclient/src/main/java/org/apache/http/client/utils/URIBuilder.java
----------------------------------------------------------------------
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 91f198c..0a79b4a 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
@@ -152,7 +152,7 @@ public class URIBuilder {
             }
             if (this.encodedQuery != null) {
                 sb.append("?").append(this.encodedQuery);
-            } else if (this.queryParams != null) {
+            } else if (this.queryParams != null && !this.queryParams.isEmpty()) {
                 sb.append("?").append(encodeUrlForm(this.queryParams));
             } else if (this.query != null) {
                 sb.append("?").append(encodeUric(this.query));

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/2e303b85/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java
----------------------------------------------------------------------
diff --git a/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java b/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java
index 8bca89e..f96178b 100644
--- a/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java
+++ b/httpclient/src/test/java/org/apache/http/client/utils/TestURIBuilder.java
@@ -30,6 +30,7 @@ import java.net.URI;
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.http.Consts;
@@ -131,6 +132,22 @@ public class TestURIBuilder {
     }
 
     @Test
+    public void testSetParametersWithEmptyArg() throws Exception {
+        final URI uri = new URI("http", null, "localhost", 80, "/test", "param=test", null);
+        final URIBuilder uribuilder = new URIBuilder(uri).setParameters();
+        final URI result = uribuilder.build();
+        Assert.assertEquals(new URI("http://localhost:80/test"), result);
+    }
+
+    @Test
+    public void testSetParametersWithEmptyList() throws Exception {
+        final URI uri = new URI("http", null, "localhost", 80, "/test", "param=test", null);
+        final URIBuilder uribuilder = new URIBuilder(uri).setParameters(Arrays.<NameValuePair>asList());
+        final URI result = uribuilder.build();
+        Assert.assertEquals(new URI("http://localhost:80/test"), result);
+    }
+
+    @Test
     public void testParameterWithSpecialChar() throws Exception {
         final URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
         final URIBuilder uribuilder = new URIBuilder(uri).addParameter("param", "1 + 1 = 2")