You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2024/06/04 09:52:32 UTC

(struts) branch fix/WW-5423-query-params created (now 3e72844fd)

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

lukaszlenart pushed a change to branch fix/WW-5423-query-params
in repository https://gitbox.apache.org/repos/asf/struts.git


      at 3e72844fd WW-5423 Fixes returning null instead of empty array in case of non-existing param

This branch includes the following new commits:

     new 3e72844fd WW-5423 Fixes returning null instead of empty array in case of non-existing param

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(struts) 01/01: WW-5423 Fixes returning null instead of empty array in case of non-existing param

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch fix/WW-5423-query-params
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 3e72844fd042a874803029c84ce159dc8e7a4e18
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Tue Jun 4 11:52:19 2024 +0200

    WW-5423 Fixes returning null instead of empty array in case of non-existing param
---
 .../struts2/dispatcher/multipart/AbstractMultiPartRequest.java     | 7 +++++--
 .../org/apache/struts2/dispatcher/multipart/MultiPartRequest.java  | 1 +
 .../struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java | 2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java
index 630d2ca43..f1b254238 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java
@@ -372,8 +372,11 @@ public abstract class AbstractMultiPartRequest implements MultiPartRequest {
      * @see org.apache.struts2.dispatcher.multipart.MultiPartRequest#getParameterValues(java.lang.String)
      */
     public String[] getParameterValues(String name) {
-        return parameters.getOrDefault(name, Collections.emptyList())
-                .toArray(String[]::new);
+        List<String> values = parameters.get(name);
+        if (values == null) {
+            return null;
+        }
+        return values.toArray(new String[0]);
     }
 
     /* (non-Javadoc)
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java
index 72392cd6f..dd801d306 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/MultiPartRequest.java
@@ -95,6 +95,7 @@ public interface MultiPartRequest {
     /**
      * Returns a list of all parameter values associated with a parameter name. If there is only
      * one parameter value per name the resulting array will be of length 1.
+     * If the parameter doesn't exist, null should be returned instead of empty array.
      *
      * @param name the name of the parameter.
      * @return an array of all values associated with the parameter name.
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java b/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java
index fb30bb289..25b86d6b2 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequestTest.java
@@ -458,6 +458,8 @@ abstract class AbstractMultiPartRequestTest {
                 .isEqualTo("short text");
         assertThat(multiPart.getParameterValues("multi"))
                 .containsOnly("multi1", "multi2");
+        assertThat(multiPart.getParameterValues("not-existing"))
+                .isNull();
     }
 
     @Test