martinc 2003/03/15 14:34:22
Modified: fileupload/src/java/org/apache/commons/fileupload
FileUpload.java
fileupload/src/test/org/apache/commons/fileupload
FileUploadTest.java
Log:
Check for multipart boundary and throw an exception if it isn't there.
Initialise sizeMax to allow unlimited upload size by default.
Fix test to break for the right reason and be explicit about it.
Revision Changes Path
1.18 +13 -6
jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/FileUpload.java
Index: FileUpload.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/FileUpload.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FileUpload.java 3 Mar 2003 06:23:39 -0000 1.17
+++ FileUpload.java 15 Mar 2003 22:34:22 -0000 1.18
@@ -185,7 +185,7 @@
/**
* The maximum size permitted for an uploaded file.
*/
- private int sizeMax;
+ private int sizeMax = -1;
/**
@@ -413,8 +413,15 @@
try
{
+ int boundaryIndex = contentType.indexOf("boundary=");
+ if (boundaryIndex < 0)
+ {
+ throw new FileUploadException(
+ "the request was rejected because "
+ + "no multipart boundary was found");
+ }
byte[] boundary = contentType.substring(
- contentType.indexOf("boundary=") + 9).getBytes();
+ boundaryIndex + 9).getBytes();
InputStream input = (InputStream) req.getInputStream();
1.8 +11 -12
jakarta-commons/fileupload/src/test/org/apache/commons/fileupload/FileUploadTest.java
Index: FileUploadTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/fileupload/src/test/org/apache/commons/fileupload/FileUploadTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FileUploadTest.java 8 Mar 2003 18:30:03 -0000 1.7
+++ FileUploadTest.java 15 Mar 2003 22:34:22 -0000 1.8
@@ -68,18 +68,17 @@
{
public void testWithInvalidRequest()
{
- HttpServletRequest hsr =
HttpServletRequestFactory.createInvalidHttpServletRequest();
-
FileUpload fu = null;
fu = new FileUpload();
HttpServletRequest req =
HttpServletRequestFactory.createInvalidHttpServletRequest();
-
+
+
try
{
fu.parseRequest(req);
- fail("expected exception was not thrown");
+ fail("testWithInvalidRequest: expected exception was not thrown");
}
catch (FileUploadException expected)
{
@@ -91,21 +90,23 @@
public void testWithNullContentType()
{
- FileUpload fu = null;
-
- fu = new FileUpload();
+ FileUpload fu = new FileUpload();
HttpServletRequest req =
HttpServletRequestFactory.createHttpServletRequestWithNullContentType();
try
{
fu.parseRequest(req);
- fail("expected exception was not thrown");
+ fail("testWithNullContentType: expected exception was not thrown");
}
- catch (FileUploadException expected)
+ catch (FileUpload.InvalidContentTypeException expected)
{
// this exception is expected
}
+ catch (FileUploadException unexpected)
+ {
+ fail("testWithNullContentType: unexpected exception was thrown");
+ }
}
@@ -124,9 +125,7 @@
"filename2"
};
- FileUpload fu = null;
-
- fu = new FileUpload();
+ FileUpload fu = new FileUpload();
HttpServletRequest req =
HttpServletRequestFactory.createValidHttpServletRequest(fileNames);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]