408446 Multipart parsing issue with boundry and charset in ContentType header
This commit is contained in:
parent
b6d1158c22
commit
053408254e
|
@ -698,6 +698,39 @@ public class MultipartFilterTest
|
|||
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
|
||||
assertTrue(response.getContent().contains("aaaa,bbbbb"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testContentTypeWithCharSet() throws Exception
|
||||
{
|
||||
// generated and parsed test
|
||||
HttpTester.Request request = HttpTester.newRequest();
|
||||
HttpTester.Response response;
|
||||
|
||||
// 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 = HttpTester.parseResponse(tester.getResponses(request.generate()));
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
assertTrue(response.getContent().indexOf("brown cow")>=0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* see the testParameterMap test
|
||||
*
|
||||
|
|
|
@ -467,8 +467,13 @@ public class MultiPartInputStreamParser
|
|||
_tmpDir.mkdirs();
|
||||
|
||||
String contentTypeBoundary = "";
|
||||
if (_contentType.indexOf("boundary=") >= 0)
|
||||
contentTypeBoundary = QuotedStringTokenizer.unquote(value(_contentType.substring(_contentType.indexOf("boundary="))).trim());
|
||||
int bstart = _contentType.indexOf("boundary=");
|
||||
if (bstart >= 0)
|
||||
{
|
||||
int bend = _contentType.indexOf(";", bstart);
|
||||
bend = (bend < 0? _contentType.length(): bend);
|
||||
contentTypeBoundary = QuotedStringTokenizer.unquote(value(_contentType.substring(bstart,bend)).trim());
|
||||
}
|
||||
|
||||
String boundary="--"+contentTypeBoundary;
|
||||
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
|
||||
|
|
|
@ -529,6 +529,28 @@ public class MultiPartInputStreamTest
|
|||
assertThat(baos.toString("UTF-8"), is("Other"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharsetEncoding () throws Exception
|
||||
{
|
||||
String contentType = "multipart/form-data; boundary=TheBoundary; charset=ISO-8859-1";
|
||||
String str = "--TheBoundary\r"+
|
||||
"content-disposition: form-data; name=\"field1\"\r"+
|
||||
"\r"+
|
||||
"\nJoe Blow\n"+
|
||||
"\r"+
|
||||
"--TheBoundary--\r";
|
||||
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(str.getBytes()),
|
||||
contentType,
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
Collection<Part> parts = mpis.getParts();
|
||||
//assertThat(parts.size(), is(1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBadlyEncodedFilename() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue