Merge remote-tracking branch 'origin/jetty-7' into jetty-8
Conflicts: jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
This commit is contained in:
commit
259aac6463
|
@ -172,7 +172,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
|
||||
|
|
|
@ -473,8 +473,13 @@ public class MultiPartInputStream
|
|||
_tmpDir.mkdirs();
|
||||
|
||||
String contentTypeBoundary = "";
|
||||
if (_contentType.indexOf("boundary=") >= 0)
|
||||
contentTypeBoundary = QuotedStringTokenizer.unquote(value(_contentType.substring(_contentType.indexOf("boundary=")), true).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), true).trim());
|
||||
}
|
||||
|
||||
String boundary="--"+contentTypeBoundary;
|
||||
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
|
||||
|
|
|
@ -521,6 +521,27 @@ public class MultiPartInputStreamTest extends TestCase
|
|||
assertThat(baos.toString("UTF-8"), is("Other"));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
MultiPartInputStream mpis = new MultiPartInputStream(new ByteArrayInputStream(str.getBytes()),
|
||||
contentType,
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
Collection<Part> parts = mpis.getParts();
|
||||
assertThat(parts.size(), is(1));
|
||||
}
|
||||
|
||||
|
||||
public void testBadlyEncodedFilename() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue