Merge remote-tracking branch 'origin/jetty-8'
Conflicts: jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStream.java jetty-util/src/test/java/org/eclipse/jetty/util/MultiPartInputStreamTest.java
This commit is contained in:
commit
a9247d6617
|
@ -471,10 +471,12 @@ public class MultiPartInputStreamParser
|
|||
|
||||
// Get first boundary
|
||||
String line=((ReadLineInputStream)_in).readLine();
|
||||
if(line==null || !line.equals(boundary))
|
||||
{
|
||||
|
||||
if (line == null || line.length() == 0)
|
||||
throw new IOException("Missing content for multipart request");
|
||||
|
||||
if (!line.equals(boundary))
|
||||
throw new IOException("Missing initial multi part boundary");
|
||||
}
|
||||
|
||||
// Read each part
|
||||
boolean lastPart=false;
|
||||
|
|
|
@ -51,7 +51,11 @@ public class ReadLineInputStream extends BufferedInputStream
|
|||
int b=super.read();
|
||||
if (b==-1)
|
||||
{
|
||||
int m=markpos;
|
||||
markpos=-1;
|
||||
if (pos>m)
|
||||
return new String(buf,m,pos-m, StringUtil.__UTF8_CHARSET);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -159,13 +159,83 @@ public class MultiPartInputStreamTest
|
|||
{
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(_multi.getBytes()),
|
||||
"Content-type: text/plain",
|
||||
"Content-type: text/plain",
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
assertTrue(mpis.getParts().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoBody()
|
||||
throws Exception
|
||||
{
|
||||
String body = "";
|
||||
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(body.getBytes()),
|
||||
_contentType,
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
try
|
||||
{
|
||||
mpis.getParts();
|
||||
fail ("Multipart missing body");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
assertTrue(e.getMessage().startsWith("Missing content"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhitespaceBodyWithCRLF()
|
||||
throws Exception
|
||||
{
|
||||
String whitespace = " \n\n\n\r\n\r\n\r\n\r\n";
|
||||
|
||||
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(whitespace.getBytes()),
|
||||
_contentType,
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
try
|
||||
{
|
||||
mpis.getParts();
|
||||
fail ("Multipart missing body");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
assertTrue(e.getMessage().startsWith("Missing initial"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhitespaceBody()
|
||||
throws Exception
|
||||
{
|
||||
String whitespace = " ";
|
||||
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartInputStreamParser mpis = new MultiPartInputStreamParser(new ByteArrayInputStream(whitespace.getBytes()),
|
||||
_contentType,
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
try
|
||||
{
|
||||
mpis.getParts();
|
||||
fail ("Multipart missing body");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
assertTrue(e.getMessage().startsWith("Missing initial"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoLimits()
|
||||
throws Exception
|
||||
|
|
Loading…
Reference in New Issue