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:
Jan Bartel 2012-12-14 12:08:03 +11:00
commit a9247d6617
3 changed files with 80 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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