[
https://issues.apache.org/jira/browse/WW-5388?focusedWorklogId=920249&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-920249
]
ASF GitHub Bot logged work on WW-5388:
--------------------------------------
Author: ASF GitHub Bot
Created on: 21/May/24 15:11
Start Date: 21/May/24 15:11
Worklog Time Spent: 10m
Work Description: criderp commented on code in PR #861:
URL: https://github.com/apache/struts/pull/861#discussion_r1608506180
##########
core/src/main/java/org/apache/struts2/dispatcher/multipart/AbstractMultiPartRequest.java:
##########
@@ -171,4 +298,109 @@ protected String getCanonicalName(final String
originalFileName) {
return fileName;
}
+ protected String sanitizeNewlines(String before) {
+ return before.replaceAll("\\R", "_");
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getErrors()
+ */
+ public List<LocalizedMessage> getErrors() {
+ return errors;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFileParameterNames()
+ */
+ public Enumeration<String> getFileParameterNames() {
+ return Collections.enumeration(uploadedFiles.keySet());
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getContentType(java.lang.String)
+ */
+ public String[] getContentType(String fieldName) {
+ return uploadedFiles.getOrDefault(fieldName,
Collections.emptyList()).stream()
+ .map(UploadedFile::getContentType)
+ .toArray(String[]::new);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFile(java.lang.String)
+ */
+ @SuppressWarnings("unchecked")
+ public UploadedFile<T>[] getFile(String fieldName) {
+ return uploadedFiles.getOrDefault(fieldName, Collections.emptyList())
+ .toArray(UploadedFile[]::new);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFileNames(java.lang.String)
+ */
+ public String[] getFileNames(String fieldName) {
+ return uploadedFiles.getOrDefault(fieldName,
Collections.emptyList()).stream()
+ .map(file -> getCanonicalName(file.getName()))
+ .toArray(String[]::new);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getFilesystemName(java.lang.String)
+ */
+ public String[] getFilesystemName(String fieldName) {
+ return uploadedFiles.getOrDefault(fieldName,
Collections.emptyList()).stream()
+ .map(UploadedFile::getAbsolutePath)
+ .toArray(String[]::new);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getParameter(java.lang.String)
+ */
+ public String getParameter(String name) {
+ List<String> paramValue = parameters.getOrDefault(name,
Collections.emptyList());
+ if (!paramValue.isEmpty()) {
+ return paramValue.get(0);
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.struts2.dispatcher.multipart.MultiPartRequest#getParameterNames()
+ */
+ public Enumeration<String> getParameterNames() {
+ return Collections.enumeration(parameters.keySet());
+ }
+
+ /* (non-Javadoc)
+ * @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);
Review Comment:
This change broke query parameters in multipart requests. Their values are
being lost. The old implementation returned null if the parameter didn't exist,
but it now returns an empty array.
`MultiPartRequestWrapper::getParameterValues` relies on the fact that it
returns null, though, so it's not working correctly anymore.
This is the old implementation:
```java
public String[] getParameterValues(String name) {
List<String> v = params.get(name);
if (v != null && !v.isEmpty()) {
return v.toArray(new String[0]);
}
return null;
}
```
And this is the `MultiPartRequestWrapper` method that doesn't work correctly
after the change:
```java
public String[] getParameterValues(String name) {
return ((multi == null) || (multi.getParameterValues(name) == null)) ?
super.getParameterValues(name) : multi.getParameterValues(name);
}
```
Issue Time Tracking
-------------------
Worklog Id: (was: 920249)
Time Spent: 11h 10m (was: 11h)
> Upgrade Commons Fileupload to FileUpload Jakarta Servlet 6
> ----------------------------------------------------------
>
> Key: WW-5388
> URL: https://issues.apache.org/jira/browse/WW-5388
> Project: Struts 2
> Issue Type: Improvement
> Components: Core
> Reporter: Lukasz Lenart
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 7.0.0
>
> Time Spent: 11h 10m
> Remaining Estimate: 0h
>
> There is a new version of JakartaEE FileUpload
> {code:xml}
> <dependency>
> <groupId>org.apache.commons</groupId>
> <artifactId>commons-fileupload2-jakarta-servlet6</artifactId>
> <version>2.0.0-M2</version>
> </dependency>
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)