This is an automated email from the ASF dual-hosted git repository.
milamber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
The following commit(s) were added to refs/heads/master by this push:
new b90f122b20 Bug #5807 - Fix an ArrayIndexOutOfBoundsException on HTTP
parameters line on special case when key and value are empty, i.e.:
"k1=v1&=&k2=v2 (#5812)
b90f122b20 is described below
commit b90f122b2074a9790cce8ec23c9e361528c83d51
Author: Milamber <[email protected]>
AuthorDate: Sun Apr 23 17:11:12 2023 +0000
Bug #5807 - Fix an ArrayIndexOutOfBoundsException on HTTP parameters line
on special case when key and value are empty, i.e.: "k1=v1&=&k2=v2 (#5812)
Thanks to Felix for code improvement
---
.../protocol/http/visualizers/RequestViewHTTP.java | 4 +-
.../http/visualizers/RequestViewHTTPTest.java | 47 ++++++++++++++++++++++
xdocs/changes.xml | 1 +
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
index feb6494cbe..a4ade6e40a 100644
---
a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
+++
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTP.java
@@ -287,6 +287,9 @@ public class RequestViewHTTP implements RequestView {
String[] params = query.split(PARAM_CONCATENATE);
for (String param : params) {
String[] paramSplit = param.split("=");
+ if (paramSplit.length == 0) {
+ continue; // We found no key-/value-pair, so continue on the
next param
+ }
String name = decodeQuery(paramSplit[0]);
// hack for SOAP request (generally)
@@ -318,7 +321,6 @@ public class RequestViewHTTP implements RequestView {
}
map.put(name, known);
}
-
return map;
}
diff --git
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
index 28279d8287..974c992498 100644
---
a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
+++
b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/visualizers/RequestViewHTTPTest.java
@@ -17,11 +17,21 @@
package org.apache.jmeter.protocol.http.visualizers;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
public class RequestViewHTTPTest {
@@ -191,4 +201,41 @@ public class RequestViewHTTPTest {
Assertions.assertEquals(query, param1.getValue()[0]);
Assertions.assertTrue(StringUtils.isBlank(param1.getKey()));
}
+
+ @SafeVarargs
+ private static Map<String, List<String>> mapOf(Pair<String, String>...
args) {
+ Map<String, List<String>> results = new HashMap<>();
+ Arrays.stream(args)
+ .forEach(arg -> results.put(arg.getKey(),
Arrays.asList(arg.getValue().split(","))));
+ return results;
+ }
+
+ private static Stream<Arguments> data() {
+ return Stream.of(Arguments.of("k1=v1&=&k2=v2",
+ mapOf(
+ Pair.of("k1", "v1"),
+ Pair.of("k2", "v2"))),
+ Arguments.of("=", mapOf()),
+ Arguments.of("k1=v1&=value&k2=v2",
+ mapOf(
+ Pair.of("k1", "v1"),
+ Pair.of("", "value"),
+ Pair.of("k2", "v2"))),
+ Arguments.of("a=1&a=2&=abc&=def",
+ mapOf(
+ Pair.of("a", "1,2"),
+ Pair.of("", "abc,def"))));
+ }
+
+ @ParameterizedTest
+ @MethodSource("data")
+ public void testGetQueryMapWithEmptyKeyAndValue(String query, Map<String,
List<String>> expected) {
+ Map<String, String[]> params = RequestViewHTTP.getQueryMap(query);
+ Assertions.assertNotNull(params);
+ Assertions.assertEquals(expected.size(), params.size());
+ expected.forEach((key, values) -> {
+ MatcherAssert.assertThat(params, Matchers.hasKey(key));
+ Assertions.assertArrayEquals(values.toArray(), params.get(key));
+ });
+ }
}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 508296c40a..e7033ce4eb 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -137,6 +137,7 @@ Summary
<h3>Listeners</h3>
<ul>
<li><issue>5740</issue><pr>5741</pr>Fix Aggregated Graph component to cope
with empty names of samplers</li>
+ <li><issue>5807</issue>Fix an ArrayIndexOutOfBoundsException on HTTP
parameters line on special case when key and value are empty, i.e.:
"k1=v1&=&k2=v2"</li>
</ul>
<h3>Timers, Assertions, Config, Pre- & Post-Processors</h3>