394839 Allow multipart mime with no boundary
This commit is contained in:
parent
6a194521c0
commit
1f368d269d
|
@ -117,12 +117,16 @@ public class MultiPartFilter implements Filter
|
|||
chain.doFilter(request,response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
InputStream in = new BufferedInputStream(request.getInputStream());
|
||||
String content_type=srequest.getContentType();
|
||||
|
||||
|
||||
// TODO - handle encodings
|
||||
String boundary="--"+QuotedStringTokenizer.unquote(value(content_type.substring(content_type.indexOf("boundary="))).trim());
|
||||
String contentTypeBoundary = "";
|
||||
if (content_type.indexOf("boundary=") >= 0)
|
||||
contentTypeBoundary = QuotedStringTokenizer.unquote(value(content_type.substring(content_type.indexOf("boundary="))).trim());
|
||||
|
||||
String boundary="--"+contentTypeBoundary;
|
||||
|
||||
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.eclipse.jetty.servlet.FilterMapping;
|
|||
import org.eclipse.jetty.testing.HttpTester;
|
||||
import org.eclipse.jetty.testing.ServletTester;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.QuotedStringTokenizer;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -46,6 +47,21 @@ public class MultipartFilterTest
|
|||
private ServletTester tester;
|
||||
|
||||
|
||||
public static class BoundaryServlet extends TestServlet
|
||||
{
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
|
||||
{
|
||||
assertNotNull(req.getParameter("fileName"));
|
||||
assertEquals("abc", req.getParameter("fileName"));
|
||||
assertNotNull(req.getParameter("desc"));
|
||||
assertEquals("123", req.getParameter("desc"));
|
||||
assertNotNull(req.getParameter("title"));
|
||||
assertEquals("ttt", req.getParameter("title"));
|
||||
super.doPost(req, resp);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestServlet extends DumpServlet
|
||||
{
|
||||
|
||||
|
@ -252,6 +268,53 @@ public class MultipartFilterTest
|
|||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
assertTrue(response.getContent().indexOf("brown cow")>=0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoBoundary() throws Exception
|
||||
{
|
||||
// generated and parsed test
|
||||
HttpTester request = new HttpTester();
|
||||
HttpTester response = new HttpTester();
|
||||
tester.addServlet(BoundaryServlet.class,"/testb");
|
||||
request.setMethod("POST");
|
||||
request.setVersion("HTTP/1.0");
|
||||
request.setHeader("Host","tester");
|
||||
request.setURI("/context/testb");
|
||||
|
||||
request.setHeader("Content-Type","multipart/form-data");
|
||||
|
||||
String content = "--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"fileName\"\r\n"+
|
||||
"Content-Type: text/plain; charset=US-ASCII\r\n"+
|
||||
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||
"\r\n"+
|
||||
"abc\r\n"+
|
||||
"--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"desc\"\r\n"+
|
||||
"Content-Type: text/plain; charset=US-ASCII\r\n"+
|
||||
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||
"\r\n"+
|
||||
"123\r\n"+
|
||||
"--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"title\"\r\n"+
|
||||
"Content-Type: text/plain; charset=US-ASCII\r\n"+
|
||||
"Content-Transfer-Encoding: 8bit\r\n"+
|
||||
"\r\n"+
|
||||
"ttt\r\n"+
|
||||
"--\r\n"+
|
||||
"Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n"+
|
||||
"Content-Type: application/octet-stream\r\n"+
|
||||
"Content-Transfer-Encoding: binary\r\n"+
|
||||
"\r\n"+
|
||||
"000\r\n"+
|
||||
"----\r\n";
|
||||
request.setContent(content);
|
||||
|
||||
response.parse(tester.getResponses(request.generate()));
|
||||
assertTrue(response.getMethod()==null);
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
}
|
||||
|
||||
/*
|
||||
* see the testParameterMap test
|
||||
|
|
Loading…
Reference in New Issue