From 10027dae424231aeb6b7a4110ddc3c308bd2038b Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sun, 22 Oct 2017 18:37:43 +0200 Subject: [PATCH 1/3] WW-4862 Extends existing regex to include charset --- .../src/main/java/org/apache/struts2/dispatcher/Dispatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 93632fa127..dcc5fe72a6 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 class Dispatcher { */ 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. From 7ad2a4214e5acc09744032202fa94bcb03d88891 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sun, 22 Oct 2017 18:38:02 +0200 Subject: [PATCH 2/3] WW-4862 Adds additional tests to cover new regex --- .../struts2/dispatcher/DispatcherTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) 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 5c7252eb54..6a20d31c8a 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java @@ -30,6 +30,7 @@ import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.interceptor.Interceptor; import com.opensymphony.xwork2.LocalizedTextProvider; +import org.apache.commons.io.Charsets; import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsInternalTestCase; import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper; @@ -40,6 +41,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.nio.charset.Charset; import java.util.Collections; import java.util.HashMap; import java.util.Locale; @@ -291,6 +293,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.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; From 4ad5ff8ade6a8b4e250e1effcccbee11a6a4b5dd Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sun, 22 Oct 2017 18:39:40 +0200 Subject: [PATCH 3/3] Drops unused imports --- .../test/java/org/apache/struts2/dispatcher/DispatcherTest.java | 2 -- 1 file changed, 2 deletions(-) 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 6a20d31c8a..7e25fb11fe 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java @@ -30,7 +30,6 @@ import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.interceptor.Interceptor; import com.opensymphony.xwork2.LocalizedTextProvider; -import org.apache.commons.io.Charsets; import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsInternalTestCase; import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper; @@ -41,7 +40,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.nio.charset.Charset; import java.util.Collections; import java.util.HashMap; import java.util.Locale;