From 13c56e81f5ae7f4d0989945a4594cf88fd96e9e1 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Mon, 20 May 2013 15:45:53 +1000 Subject: [PATCH] 408446 Multipart parsing issue with boundry and charset in ContentType header --- .../jetty/servlets/MultiPartFilter.java | 9 +++-- .../jetty/servlets/MultipartFilterTest.java | 33 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java index fea6d370497..c872e936faa 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java @@ -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; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java index d41228a150d..5f12d70442c 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java @@ -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