Issue Details (XML | Word | Printable)

Key: FILEUPLOAD-139
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: martynas
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Commons FileUpload

[fileupload] separator of boundary doesnt match rfc1867 examples

Created: 03/Jul/07 06:26 AM   Updated: 05/Sep/07 09:21 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.1

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works FILEUPLOAD-139.patch 2007-09-04 11:37 AM Henri Yandell 4 kB

Resolution Date: 05/Sep/07 09:21 AM


 Description  « Hide
[fileupload]
in class :
package org.apache.commons.fileupload;
public abstract class FileUploadBase {

protected byte[] getBoundary(String contentType) {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
Map params = parser.parse(contentType, ';');
String boundaryStr = (String) params.get("boundary");

if (boundaryStr == null) { return null; }
byte[] boundary;
try { boundary = boundaryStr.getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { boundary = boundaryStr.getBytes(); }
return boundary;
}

}

String : Map params = parser.parse(contentType, ';');
doesn't match http://www.ietf.org/rfc/rfc1867.txt document
because in all examples:
Content-type: multipart/form-data , boundary=AaB03x
Content-type: multipart/form-data, boundary=AaB03x
Content-type: multipart/mixed, boundary=BbC04y

boundary separated by comma (but not semicolon)



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Henri Yandell added a comment - 23/Aug/07 11:21 AM
http://www.ietf.org/rfc/rfc1521.txt uses semi-colons [the mime spec].

I guess we need to figure out whether browsers are sending semi-colons or commas. Maybe this part of the spec gets ignored.

[Completely odd fact... the Habsburgs ruled Hungary from 1521 to 1867]


martynas added a comment - 23/Aug/07 01:07 PM
"FileUpload parses HTTP requests which conform to RFC 1867, "Form-based File Upload in HTML". That is, if an HTTP request is submitted using the POST method, and with a content type of "multipart/form-data", then FileUpload can parse that request, and make the results available in a manner easily used by the caller. "

this text is copied from http://commons.apache.org/fileupload/ first paragraph
So as i understand phrase "conform to RFC 1867" it means that all spec written in this RFC should be supported.

As i see this is simple task to support both commas and semi-colons.


Henri Yandell added a comment - 24/Aug/07 05:28 PM
Why continue to support semi-colons? The spec doesn't seem to mention them.

Do browsers tend to send ; and not , as the spec says?


martynas added a comment - 27/Aug/07 06:29 AM - edited
Yes, as i looked browsers tend to send semi-colons.But not only web browsers can submit files to server using this method. For example I made some embedded device witch is sending some generated files to Server. File upload part I done using RFC 1867.I didn't look at others rfc looking if there is some mistake in this one. So i have done device which is sending files to some server. If my written script is good I tested on simple php script. There was no problem. So we produced a lot of these devices (i can't change soft in them). Then I began making server on Java using this library . So occurred a problem. At moment i use some decorator witch replaces commas to semi-colons. But as I suppose it should be fixed in library because i may be not only one who is writing simple code using this rfc without checking if its conflicting with other rfc documents.

Henri Yandell added a comment - 27/Aug/07 02:15 PM
Makes sense. Assigning to 1.2.1.

Henri Yandell added a comment - 04/Sep/07 11:37 AM
Attaching a patch which adds a new parse method to ParameterParser that can take multiple separators. It looks for the earliest one that occurs in the string to be parsed, and uses that.

Unit test also patched, as is the getBoundary method to use this new parse(String, char[]) method.


Henri Yandell added a comment - 04/Sep/07 11:41 AM
Any thoughts on the patch?

Jochen Wiedmann added a comment - 04/Sep/07 08:05 PM
After reviewing, I can't fight the feeling, that the ParameterParser could use some refactoring in order to reduce the number of similar methods. However, IMO, we should reuse mime4j in the next version anyways, so that can be ignored for now. Go on, Henri!

Henri Yandell added a comment - 05/Sep/07 09:21 AM
svn ci -m "Applying the patch from FILEUPLOAD-139 so that comma separators are supported (as per rfc1867) as well as semi-colons"

Sending src/java/org/apache/commons/fileupload/FileUploadBase.java
Sending src/java/org/apache/commons/fileupload/ParameterParser.java
Sending src/test/org/apache/commons/fileupload/ParameterParserTest.java
Transmitting file data ...
Committed revision 572918.