[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpcomponents-commits
Subject:    httpcomponents-client git commit: HTTPCLIENT-1876. Improve the buildString() method in URIBuilder.
From:       olegk () apache ! org
Date:       2017-10-25 14:58:01
Message-ID: 6f6da5b395b445b7aa5acbc85a4bc1dd () git ! apache ! org
[Download RAW message or body]

Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.6.x cc58de13c -> 11190331d


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/11190331
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/11190331
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/11190331

Branch: refs/heads/4.6.x
Commit: 11190331d38f38fc0768c7c8d0ca5a726f910984
Parents: cc58de1
Author: aleh_struneuski <aleh_struneuski@epam.com>
Authored: Wed Oct 25 11:02:42 2017 +0300
Committer: aleh_struneuski <aleh_struneuski@epam.com>
Committed: Wed Oct 25 11:02:42 2017 +0300

----------------------------------------------------------------------
 .../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/11190331/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 \
                5d9d897..8fbf67a 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
@@ -163,7 +163,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/11190331/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 \
                5095d39..7a63e7e 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
@@ -31,6 +31,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;
@@ -132,6 +133,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")


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic