Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WW-5423] Fixes returning null instead of empty array in case of non-existing param #954

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,11 @@ public Enumeration<String> getParameterNames() {
* @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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void uploadedFilesToDisk() throws IOException {
.isEmpty();

assertThat(multiPart.getFileParameterNames().asIterator()).toIterable()
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsOnly("file1", "file2");
assertThat(multiPart.getFile("file1")).allSatisfy(file -> {
assertThat(file.isFile())
Expand Down Expand Up @@ -142,7 +142,7 @@ public void uploadedMultipleFilesToDisk() throws IOException {
.isEmpty();

assertThat(multiPart.getFileParameterNames().asIterator()).toIterable()
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsOnly("file1");
assertThat(multiPart.getFile("file1")).allSatisfy(file -> {
if (Objects.equals(file.getName(), "test1.csv")) {
Expand Down Expand Up @@ -193,7 +193,7 @@ public void uploadedFilesWithLargeBuffer() throws IOException {
.isEmpty();

assertThat(multiPart.getFileParameterNames().asIterator()).toIterable()
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsOnly("file1", "file2");
assertThat(multiPart.getFile("file1")).allSatisfy(file -> {
assertThat(file.isFile())
Expand Down Expand Up @@ -240,7 +240,7 @@ public void cleanUp() throws IOException {
.isEmpty();

assertThat(multiPart.getFileParameterNames().asIterator()).toIterable()
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsOnly("file1", "file2");
assertThat(multiPart.getFile("file1")).allSatisfy(file -> {
assertThat(file.isFile())
Expand Down Expand Up @@ -306,7 +306,7 @@ public void nonMultiPartUpload() throws IOException {
.containsExactly("struts.messages.upload.error.FileUploadContentTypeException");

assertThat(multiPart.getFileParameterNames().asIterator()).toIterable()
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.isEmpty();
}

Expand Down Expand Up @@ -410,7 +410,7 @@ public void mismatchCharset() throws IOException {
.isEmpty();

assertThat(multiPart.getFileParameterNames().asIterator()).toIterable()
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsOnly("file1");
assertThat(multiPart.getFile("file1")).allSatisfy(file -> {
assertThat(file.isFile())
Expand Down Expand Up @@ -458,6 +458,8 @@ public void normalFields() throws IOException {
.isEqualTo("short text");
assertThat(multiPart.getParameterValues("multi"))
.containsOnly("multi1", "multi2");
assertThat(multiPart.getParameterValues("not-existing"))
.isNull();
}

@Test
Expand Down
Loading