martinc 2004/10/10 18:59:49
Modified: fileupload/src/java/org/apache/commons/fileupload
FileUploadBase.java
Log:
Bug #21269 - handle quoted boundary specification.
Revision Changes Path
1.8 +24 -9
jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/FileUploadBase.java
Index: FileUploadBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/FileUploadBase.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FileUploadBase.java 10 Oct 2004 21:59:48 -0000 1.7
+++ FileUploadBase.java 11 Oct 2004 01:59:49 -0000 1.8
@@ -273,15 +273,14 @@
try
{
- int boundaryIndex = contentType.indexOf("boundary=");
- if (boundaryIndex < 0)
+ String boundaryStr = getBoundary(contentType);
+ if (boundaryStr == null)
{
throw new FileUploadException(
"the request was rejected because "
+ "no multipart boundary was found");
}
- byte[] boundary = contentType.substring(
- boundaryIndex + 9).getBytes();
+ byte[] boundary = boundaryStr.getBytes();
InputStream input = req.getInputStream();
@@ -300,10 +299,8 @@
.toLowerCase().startsWith(MULTIPART_MIXED))
{
// Multiple files.
- byte[] subBoundary =
- subContentType.substring(
- subContentType
- .indexOf("boundary=") + 9).getBytes();
+ String subBoundaryStr = getBoundary(subContentType);
+ byte[] subBoundary = subBoundaryStr.getBytes();
multi.setBoundary(subBoundary);
boolean nextSubPart = multi.skipPreamble();
while (nextSubPart)
@@ -370,6 +367,24 @@
// ------------------------------------------------------ Protected methods
+
+
+ /**
+ * Retrieves the boundary from the <code>Content-type</code> header.
+ *
+ * @param contentType The value of the content type header from which to
+ * extract the boundary value.
+ *
+ * @return The boundary, without any surrounding quotes.
+ */
+ protected String getBoundary(String contentType)
+ {
+ ParameterParser parser = new ParameterParser();
+ parser.setLowerCaseNames(true);
+ // Parameter parser can handle null input
+ Map params = parser.parse(contentType, ';');
+ return (String)params.get("boundary");
+ }
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]