[seam-commits] Seam SVN: r15578 - in branches/enterprise/WFK-2_1/jboss-seam/src: test/java/org/jboss/seam/test/unit and 1 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Jul 30 09:48:16 EDT 2013
Author: manaRH
Date: 2013-07-30 09:48:16 -0400 (Tue, 30 Jul 2013)
New Revision: 15578
Added:
branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/web/MultipartRequestImplTest.java
Modified:
branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/web/MultipartRequestImpl.java
branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/testng.xml
Log:
backported JBSEAM-4679
Modified: branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/web/MultipartRequestImpl.java
===================================================================
--- branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/web/MultipartRequestImpl.java 2013-07-30 07:40:10 UTC (rev 15577)
+++ branches/enterprise/WFK-2_1/jboss-seam/src/main/java/org/jboss/seam/web/MultipartRequestImpl.java 2013-07-30 13:48:16 UTC (rev 15578)
@@ -330,7 +330,15 @@
{
if (checkSequence(buffer, i, CR_LF))
{
- String param = (encoding == null) ?
+ // Check next CR_LF available in the buffer
+ if ( read <= i + CR_LF.length)
+ { /* if there is no space left for CRLF in the buffer,
+ force pushing of remaining (unread) bytes to the beginning of the buffer,
+ read more bytes and try again */
+ i = read;
+ break;
+ }
+ String param = (encoding == null) ?
new String(buffer, pos, i - pos - 1) :
new String(buffer, pos, i - pos - 1, encoding);
parseParams(param, ";", headers);
Modified: branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/testng.xml
===================================================================
--- branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/testng.xml 2013-07-30 07:40:10 UTC (rev 15577)
+++ branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/testng.xml 2013-07-30 13:48:16 UTC (rev 15578)
@@ -52,6 +52,7 @@
<test name="Seam Unit Tests Filters">
<classes>
<class name="org.jboss.seam.test.unit.web.MultipartRequestTest" />
+ <class name="org.jboss.seam.test.unit.web.MultipartRequestImplTest" />
<class name="org.jboss.seam.test.unit.web.IdentityRequestWrapperTest" />
</classes>
</test>
Added: branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/web/MultipartRequestImplTest.java
===================================================================
--- branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/web/MultipartRequestImplTest.java (rev 0)
+++ branches/enterprise/WFK-2_1/jboss-seam/src/test/java/org/jboss/seam/test/unit/web/MultipartRequestImplTest.java 2013-07-30 13:48:16 UTC (rev 15578)
@@ -0,0 +1,90 @@
+package org.jboss.seam.test.unit.web;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Map;
+
+import org.jboss.seam.mock.EnhancedMockHttpServletRequest;
+import org.jboss.seam.web.MultipartRequestImpl;
+import org.testng.annotations.Test;
+
+public class MultipartRequestImplTest
+{
+ private static final String CRLF = "\r\n";
+ private static final String HYPHENS = "--";
+
+ @Test
+ public void testParseRequestBasic() throws Throwable
+ {
+ String boundary = "boundary10"; //10 bytes
+
+ String data =
+ HYPHENS + boundary + CRLF +
+ "Content-Disposition: form-data; name=\"foo\"" + CRLF +
+ CRLF +
+ "bar" + CRLF +
+ HYPHENS + boundary + HYPHENS;
+
+ byte[] dataBytes = data.getBytes("UTF-8");
+
+ EnhancedMockHttpServletRequest req = new EnhancedMockHttpServletRequest();
+ req.setContent(dataBytes);
+ req.setContentType("multipart/form-data; boundary=" + boundary);
+ MultipartRequestImpl r = new MultipartRequestImpl(req, false, 0);
+ Map m = r.getParameterMap();
+ assertNotNull(m);
+ assertEquals(r.getParameterValues("foo")[0], "bar");
+ }
+
+ @Test
+ public void testParseRequestBufferBoundary() throws Throwable
+ {
+
+ int bufferSize = 2048; // See MultipartRequestImpl
+
+ String boundary = "boundary10";
+
+ String paddingParameter =
+ HYPHENS + boundary + CRLF +
+ "Content-Disposition: form-data; name=\"padding\"" + CRLF +
+ CRLF;
+
+ String testParameter =
+ HYPHENS + boundary + CRLF +
+ "Content-Disposition: form-data; name=\"foo\"" + CRLF +
+ CRLF +
+ "bar" + CRLF +
+ HYPHENS + boundary + HYPHENS;
+
+ // let's put test parameter near the buffer boundary, from (bufferSize - 100) to (bufferSize + 100)
+ for (int i = -100; i < 100; i++)
+ {
+ StringBuffer buffer = new StringBuffer(bufferSize + 256);
+ buffer.append(paddingParameter);
+ int paddingSize = bufferSize - i - paddingParameter.length() - CRLF.length();
+ appendPaddingValue(buffer, paddingSize);
+ buffer.append(CRLF);
+ buffer.append(testParameter);
+ String data = buffer.toString();
+
+ byte[] dataBytes = data.getBytes("UTF-8");
+ EnhancedMockHttpServletRequest req = new EnhancedMockHttpServletRequest();
+ req.setContent(dataBytes);
+ req.setContentType("multipart/form-data; boundary=" + boundary);
+ MultipartRequestImpl r = new MultipartRequestImpl(req, false, 0);
+ Map m = r.getParameterMap();
+ assertNotNull(m);
+ assertEquals(r.getParameterValues("foo")[0], "bar");
+ }
+ }
+
+ private static StringBuffer appendPaddingValue(StringBuffer buffer, int length)
+ {
+ for (int i = 0; i < length; i++)
+ {
+ buffer.append("x");
+ }
+ return buffer;
+ }
+}
More information about the seam-commits
mailing list