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);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]