Issue #4383 - check for non multipart content type in constructor
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
0ab7751ef2
commit
f9f2ccaefa
|
@ -94,7 +94,7 @@ public class MultiPartFormInputStream
|
|||
private volatile boolean _deleteOnExit;
|
||||
private volatile boolean _writeFilesWithFilenames;
|
||||
private volatile int _bufferSize = 16 * 1024;
|
||||
private volatile State state = State.UNPARSED;
|
||||
private State state = State.UNPARSED;
|
||||
|
||||
public class MultiPart implements Part
|
||||
{
|
||||
|
@ -356,7 +356,11 @@ public class MultiPartFormInputStream
|
|||
*/
|
||||
public MultiPartFormInputStream(InputStream in, String contentType, MultipartConfigElement config, File contextTmpDir)
|
||||
{
|
||||
// Must be a multipart request.
|
||||
_contentType = contentType;
|
||||
if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
|
||||
throw new IllegalArgumentException("content type is not multipart/form-data");
|
||||
|
||||
_contextTmpDir = (contextTmpDir != null) ? contextTmpDir : new File(System.getProperty("java.io.tmpdir"));
|
||||
_config = (config != null) ? config : new MultipartConfigElement(_contextTmpDir.getAbsolutePath());
|
||||
|
||||
|
@ -520,10 +524,6 @@ public class MultiPartFormInputStream
|
|||
MultiPartParser parser = null;
|
||||
try
|
||||
{
|
||||
// if its not a multipart request, don't parse it
|
||||
if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
|
||||
return;
|
||||
|
||||
// sort out the location to which to write the files
|
||||
if (_config.getLocation() == null)
|
||||
_tmpDir = _contextTmpDir;
|
||||
|
|
|
@ -206,12 +206,10 @@ public class MultiPartFormInputStreamTest
|
|||
throws Exception
|
||||
{
|
||||
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
|
||||
MultiPartFormInputStream mpis = new MultiPartFormInputStream(new ByteArrayInputStream(_multi.getBytes()),
|
||||
"Content-type: text/plain",
|
||||
config,
|
||||
_tmpDir);
|
||||
mpis.setDeleteOnExit(true);
|
||||
assertTrue(mpis.getParts().isEmpty());
|
||||
Throwable t = assertThrows(IllegalArgumentException.class, () ->
|
||||
new MultiPartFormInputStream(new ByteArrayInputStream(_multi.getBytes()),
|
||||
"Content-type: text/plain", config, _tmpDir));
|
||||
assertThat(t.getMessage(), is("content type is not multipart/form-data"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue