408446 Multipart parsing issue with boundry and charset in ContentType header

This commit is contained in:
Jan Bartel 2013-05-20 15:45:53 +10:00
parent 51c1017b3d
commit 13c56e81f5
2 changed files with 39 additions and 3 deletions

View File

@ -125,8 +125,13 @@ public class MultiPartFilter implements Filter
// TODO - handle encodings
String contentTypeBoundary = "";
if (content_type.indexOf("boundary=") >= 0)
contentTypeBoundary = QuotedStringTokenizer.unquote(value(content_type.substring(content_type.indexOf("boundary="))).trim());
int bstart = content_type.indexOf("boundary=");
if (bstart >= 0)
{
int bend = content_type.indexOf(";", bstart);
bend = (bend < 0? content_type.length(): bend);
contentTypeBoundary = QuotedStringTokenizer.unquote(value(content_type.substring(bstart,bend)).trim());
}
String boundary="--"+contentTypeBoundary;

View File

@ -164,7 +164,38 @@ public class MultipartFilterTest
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
assertTrue(response.getContent().indexOf("brown cow")>=0);
}
@Test
public void testContentTypeWithCharset() throws Exception
{
// generated and parsed test
HttpTester request = new HttpTester();
HttpTester response = new HttpTester();
// test GET
request.setMethod("POST");
request.setVersion("HTTP/1.0");
request.setHeader("Host","tester");
request.setURI("/context/dump");
String boundary="XyXyXy";
request.setHeader("Content-Type","multipart/form-data; boundary=\""+boundary+"\"; charset=ISO-8859-1");
String content = "--" + boundary + "\r\n"+
"Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n"+
"Content-Type: application/octet-stream\r\n\r\n"+
"How now brown cow."+
"\r\n--" + boundary + "--\r\n\r\n";
request.setContent(content);
response.parse(tester.getResponses(request.generate()));
assertTrue(response.getMethod()==null);
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
assertTrue(response.getContent().indexOf("brown cow")>=0);
}
@Test
public void testEncodedPost() throws Exception