You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2017/12/15 21:23:50 UTC
httpcomponents-core git commit: HTTPCORE-501
org.apache.http.client.utils.URLEncodedUtils.parse() should return a new
ArrayList when there are no query parameters.
Repository: httpcomponents-core
Updated Branches:
refs/heads/master 72063bbca -> 496f5bf39
HTTPCORE-501 org.apache.http.client.utils.URLEncodedUtils.parse() should
return a new ArrayList when there are no query parameters.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/496f5bf3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/496f5bf3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/496f5bf3
Branch: refs/heads/master
Commit: 496f5bf390c10626486665ee1c8f859d3dc4888d
Parents: 72063bb
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Dec 15 14:23:47 2017 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Dec 15 14:23:47 2017 -0700
----------------------------------------------------------------------
RELEASE_NOTES.txt | 4 ++++
.../java/org/apache/hc/core5/net/URLEncodedUtils.java | 11 +++++++----
.../org/apache/hc/core5/net/TestURLEncodedUtils.java | 8 ++++++++
3 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/496f5bf3/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index fa4e449..16ebc7c 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -10,6 +10,10 @@ Changelog
* HTTPCORE-499 Make interface Header extend NameValuePair
Contributed by Gary Gregory <ggregory at apache.org>
+* HTTPCORE-501 org.apache.http.client.utils.URLEncodedUtils.parse()
+ should return a new ArrayList when there are no query parameters.
+ Contributed by Gary Gregory <ggregory at apache.org>
+
Release 5.0-BETA1
-------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/496f5bf3/httpcore5/src/main/java/org/apache/hc/core5/net/URLEncodedUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/URLEncodedUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/net/URLEncodedUtils.java
index 7642586..e4f8d4f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/net/URLEncodedUtils.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/URLEncodedUtils.java
@@ -34,7 +34,6 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.BitSet;
-import java.util.Collections;
import java.util.List;
import org.apache.hc.core5.http.NameValuePair;
@@ -83,7 +82,7 @@ public class URLEncodedUtils {
if (query != null && !query.isEmpty()) {
return parse(query, charset);
}
- return Collections.emptyList();
+ return createEmptyList();
}
/**
@@ -100,7 +99,7 @@ public class URLEncodedUtils {
*/
public static List<NameValuePair> parse(final String s, final Charset charset) {
if (s == null) {
- return Collections.emptyList();
+ return createEmptyList();
}
final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s);
@@ -123,7 +122,7 @@ public class URLEncodedUtils {
*/
public static List<NameValuePair> parse(final String s, final Charset charset, final char... separators) {
if (s == null) {
- return Collections.emptyList();
+ return createEmptyList();
}
final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s);
@@ -332,6 +331,10 @@ public class URLEncodedUtils {
private static final int RADIX = 16;
+ private static List<NameValuePair> createEmptyList() {
+ return new ArrayList<>(0);
+ }
+
private static String urlEncode(
final String content,
final Charset charset,
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/496f5bf3/httpcore5/src/test/java/org/apache/hc/core5/net/TestURLEncodedUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURLEncodedUtils.java b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURLEncodedUtils.java
index 8d1b314..6a0aaaf 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURLEncodedUtils.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURLEncodedUtils.java
@@ -232,6 +232,14 @@ public class TestURLEncodedUtils {
}
@Test
+ public void testEmptyQuery() throws Exception {
+ final List<NameValuePair> result = URLEncodedUtils.parse("", StandardCharsets.UTF_8);
+ Assert.assertEquals(0, result.size());
+ // [HTTPCLIENT-1889]:
+ result.add(new BasicNameValuePair("key", "value"));
+ }
+
+ @Test
public void testFormat() throws Exception {
final List <NameValuePair> params = new ArrayList<>();
Assert.assertEquals(0, URLEncodedUtils.format(params, StandardCharsets.US_ASCII).length());