Commits

Anonymous committed 4e1535e

- commons Upload encoding bug

Issue number: WW-1335
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2670573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (2)

src/java/com/opensymphony/webwork/dispatcher/DispatcherUtils.java

             locale = LocalizedTextUtil.localeFromString(Configuration.getString(WebWorkConstants.WEBWORK_LOCALE), request.getLocale());
         }
 
-        if (encoding != null && !MultiPartRequest.isMultiPart(request)) {
+        if (encoding != null) {
             try {
                 request.setCharacterEncoding(encoding);
             } catch (Exception e) {

src/test/com/opensymphony/webwork/dispatcher/DispatcherUtilsTest.java

 
 import java.util.Locale;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
 import org.springframework.mock.web.MockServletContext;
 
+import com.opensymphony.webwork.WebWorkConstants;
+import com.opensymphony.webwork.WebWorkTestCase;
+import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.xwork.util.LocalizedTextUtil;
 
-import junit.framework.TestCase;
-
 /**
  * Test case for DispatcherUtils.
  * 
  * @author tm_jee
  * @version $Date$ $Id$
  */
-public class DispatcherUtilsTest extends TestCase {
+public class DispatcherUtilsTest extends WebWorkTestCase {
 
 	public void testDefaultResurceBundlePropertyLoaded() throws Exception {
         Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties
 				"Error uploading: some error messages");
 	}
 	
+	public void testPrepareSetEncodingProperly() throws Exception {
+		HttpServletRequest req = new MockHttpServletRequest();
+		HttpServletResponse res = new MockHttpServletResponse();
+		
+		Configuration.set(WebWorkConstants.WEBWORK_I18N_ENCODING, "utf-8");
+		
+		
+		DispatcherUtils du = DispatcherUtils.getInstance();
+		du.prepare(req, res);
+		
+		assertEquals(req.getCharacterEncoding(), "utf-8");
+	}
+	
+	public void testPrepareSetEncodingPropertyWithMultipartRequest() throws Exception {
+		MockHttpServletRequest req = new MockHttpServletRequest();
+		MockHttpServletResponse res = new MockHttpServletResponse();
+		
+		req.setContentType("multipart/form-data");
+		Configuration.set(WebWorkConstants.WEBWORK_I18N_ENCODING, "utf-8");
+		
+		
+		DispatcherUtils du = DispatcherUtils.getInstance();
+		du.prepare(req, res);
+		
+		assertEquals(req.getCharacterEncoding(), "utf-8");
+	}
 }