martinc 2004/10/16 17:58:35
Modified: fileupload/src/java/org/apache/commons/fileupload
MultipartStream.java
fileupload/src/test/org/apache/commons/fileupload
FileUploadTest.java
Log:
Bug #30061 - Workaround for Mac IE5 bug. Thanks to Justin Sampson for the
patch and tests for this vexing issue.
Revision Changes Path
1.16 +12 -1
jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/MultipartStream.java
Index: MultipartStream.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/MultipartStream.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- MultipartStream.java 25 Jul 2004 04:47:17 -0000 1.15
+++ MultipartStream.java 17 Oct 2004 00:58:35 -0000 1.16
@@ -339,6 +339,17 @@
try
{
marker[0] = readByte();
+ if (marker[0] == 0x0A)
+ {
+ // Work around IE5 Mac bug with input type=image.
+ // Because the boundary delimiter, not including the trailing
+ // CRLF, must not appear within any file (RFC 2046, section
+ // 5.1.1), we know the missing CR is due to a buggy browser
+ // rather than a file containing something similar to a
+ // boundary.
+ return true;
+ }
+
marker[1] = readByte();
if (arrayequals(marker, STREAM_TERMINATOR, 2))
{
1.12 +58 -4
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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FileUploadTest.java 14 Oct 2004 04:48:15 -0000 1.11
+++ FileUploadTest.java 17 Oct 2004 00:58:35 -0000 1.12
@@ -81,7 +81,9 @@
}
- public void testFileUpload() throws IOException, FileUploadException {
+ public void testFileUpload()
+ throws IOException, FileUploadException
+ {
List fileItems = parseUpload("-----1234\r\n" +
"Content-Disposition: form-data; name=\"file\";
filename=\"foo.tab\"\r\n" +
"Content-Type: text/whatever\r\n" +
@@ -129,7 +131,9 @@
/**
* This is what the browser does if you submit the form without choosing a file.
*/
- public void testEmptyFile() throws UnsupportedEncodingException,
FileUploadException {
+ public void testEmptyFile()
+ throws UnsupportedEncodingException, FileUploadException
+ {
List fileItems = parseUpload ("-----1234\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"\"\r\n" +
"\r\n" +
@@ -143,7 +147,58 @@
assertEquals("", file.getName());
}
- private List parseUpload(String content) throws UnsupportedEncodingException,
FileUploadException {
+ /**
+ * Internet Explorer 5 for the Mac has a bug where the carriage
+ * return is missing on any boundary line immediately preceding
+ * an input with type=image. (type=submit does not have the bug.)
+ */
+ public void testIE5MacBug()
+ throws UnsupportedEncodingException, FileUploadException
+ {
+ List fileItems = parseUpload("-----1234\r\n" +
+ "Content-Disposition: form-data; name=\"field1\"\r\n" +
+ "\r\n" +
+ "fieldValue\r\n" +
+ "-----1234\n" + // NOTE \r missing
+ "Content-Disposition: form-data; name=\"submitName.x\"\r\n" +
+ "\r\n" +
+ "42\r\n" +
+ "-----1234\n" + // NOTE \r missing
+ "Content-Disposition: form-data; name=\"submitName.y\"\r\n" +
+ "\r\n" +
+ "21\r\n" +
+ "-----1234\r\n" +
+ "Content-Disposition: form-data; name=\"field2\"\r\n" +
+ "\r\n" +
+ "fieldValue2\r\n" +
+ "-----1234--\r\n");
+
+ assertEquals(4, fileItems.size());
+
+ FileItem field1 = (FileItem) fileItems.get(0);
+ assertEquals("field1", field1.getFieldName());
+ assertTrue(field1.isFormField());
+ assertEquals("fieldValue", field1.getString());
+
+ FileItem submitX = (FileItem) fileItems.get(1);
+ assertEquals("submitName.x", submitX.getFieldName());
+ assertTrue(submitX.isFormField());
+ assertEquals("42", submitX.getString());
+
+ FileItem submitY = (FileItem) fileItems.get(2);
+ assertEquals("submitName.y", submitY.getFieldName());
+ assertTrue(submitY.isFormField());
+ assertEquals("21", submitY.getString());
+
+ FileItem field2 = (FileItem) fileItems.get(3);
+ assertEquals("field2", field2.getFieldName());
+ assertTrue(field2.isFormField());
+ assertEquals("fieldValue2", field2.getString());
+ }
+
+ private List parseUpload(String content)
+ throws UnsupportedEncodingException, FileUploadException
+ {
byte[] bytes = content.getBytes("US-ASCII");
String contentType = "multipart/form-data; boundary=---1234";
@@ -156,4 +211,3 @@
}
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]