[ 
https://issues.apache.org/jira/browse/WW-4862?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16216476#comment-16216476
 ] 

ASF GitHub Bot commented on WW-4862:
------------------------------------

lukaszlenart closed pull request #176: WW-4862: Multipart regex
URL: https://github.com/apache/struts/pull/176
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java 
b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
index 93632fa12..dcc5fe72a 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
@@ -85,7 +85,7 @@
      */
     public static final String REQUEST_POST_METHOD = "POST";
 
-    public static final String MULTIPART_FORM_DATA_REGEX = 
"^multipart/form-data(; boundary=[0-9a-zA-Z'()+_,\\-./:=?]{1,70})?";
+    public static final String MULTIPART_FORM_DATA_REGEX = 
"^multipart/form-data(; 
boundary=[0-9a-zA-Z'()+_,\\-./:=?]{1,70})?(;charset=[a-zA-Z\\-0-9]{3,14})?";
 
     /**
      * Provide a thread local instance.
diff --git 
a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java 
b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
index 5c7252eb5..7e25fb11f 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
@@ -291,6 +291,36 @@ public void testMultipartSupportEnabledByDefault() throws 
Exception {
         assertTrue(du.isMultipartSupportEnabled(req));
     }
 
+    public void testIsMultipartRequest() throws Exception {
+        MockHttpServletRequest req = new MockHttpServletRequest();
+        HttpServletResponse res = new MockHttpServletResponse();
+
+        req.setMethod("POST");
+        Dispatcher du = initDispatcher(Collections.<String, String>emptyMap());
+        du.prepare(req, res);
+
+        req.setContentType("multipart/form-data");
+        assertTrue(du.isMultipartRequest(req));
+
+        req.setContentType("multipart/form-data; 
boundary=---------------------------207103069210263");
+        assertTrue(du.isMultipartRequest(req));
+
+        req.setContentType("multipart/form-data; 
boundary=---------------------------207103069210263;charset=UTF-8");
+        assertTrue(du.isMultipartRequest(req));
+
+        req.setContentType("multipart/form-data; 
boundary=---------------------------207103069210263;charset=ISO-8859-1");
+        assertTrue(du.isMultipartRequest(req));
+
+        req.setContentType("multipart/form-data; 
boundary=---------------------------207103069210263;charset=Windows-1250");
+        assertTrue(du.isMultipartRequest(req));
+
+        req.setContentType("multipart/form-data; 
boundary=---------------------------207103069210263;charset=US-ASCII");
+        assertTrue(du.isMultipartRequest(req));
+
+        req.setContentType("multipart/form-data; 
boundary=---------------------------207103069210263;charset=UTF-16LE");
+        assertTrue(du.isMultipartRequest(req));
+    }
+
     class InternalConfigurationManager extends ConfigurationManager {
        public boolean destroyConfiguration = false;
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Default Multipart validation regex is invalid due to charset encoding
> ---------------------------------------------------------------------
>
>                 Key: WW-4862
>                 URL: https://issues.apache.org/jira/browse/WW-4862
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Dispatch Filter
>    Affects Versions: 2.5.13
>         Environment: JDK8
> Tomcat 8.0
> Struts 2.5.13
>            Reporter: Paolo Perliti
>              Labels: charset, multipart, regex, struts2
>             Fix For: 2.5.14
>
>
> Struts 2.5.12 introduced a regex matches for multipart requests. 
> Struts 2.5.13 fixed WW-4818 issue, still it does fails due to charset 
> encoding being appended after the boundary marker (the regex does not match).
> Here's the header sent in browser's request:
> {code}
> Content-Type: multipart/form-data; 
> boundary=---------------------------207103069210263
> {code}
> And this is the header handled in Struts' Dispatcher wrapRequest() method:
> {code}
> multipart/form-data; 
> boundary=---------------------------207103069210263;charset=UTF-8
> {code}
> The issue seems to be related to the _applyEncoding _method (called in 
> _prepare_ method)
> {code:title=Dispatcher.java|borderStyle=solid}
>     private void applyEncoding(HttpServletRequest request, String encoding) {
>         try {
>             if (!encoding.equals(request.getCharacterEncoding())) {
>                 // if the encoding is already correctly set and the 
> parameters have been already read
>                 // do not try to set encoding because it is useless and will 
> cause an error
>                request.setCharacterEncoding(encoding);
>             }
>         } catch (Exception e) {
>             LOG.error("Error setting character encoding to '{}' - ignoring.", 
> encoding, e);
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to