martinc 2004/10/30 19:03:47
Modified: fileupload/src/java/org/apache/commons/fileupload
FileUploadBase.java
Log:
Bug #26194: Specify the encoding (ISO-8859-1) when converting the boundary
to a byte array.
Revision Changes Path
1.12 +19 -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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- FileUploadBase.java 29 Oct 2004 04:17:23 -0000 1.11
+++ FileUploadBase.java 31 Oct 2004 02:03:47 -0000 1.12
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -262,13 +263,12 @@
}
try {
- String boundaryStr = getBoundary(contentType);
- if (boundaryStr == null) {
+ byte[] boundary = getBoundary(contentType);
+ if (boundary == null) {
throw new FileUploadException(
"the request was rejected because "
+ "no multipart boundary was found");
}
- byte[] boundary = boundaryStr.getBytes();
InputStream input = req.getInputStream();
@@ -284,8 +284,7 @@
if (subContentType != null && subContentType
.toLowerCase().startsWith(MULTIPART_MIXED)) {
// Multiple files.
- String subBoundaryStr = getBoundary(subContentType);
- byte[] subBoundary = subBoundaryStr.getBytes();
+ byte[] subBoundary = getBoundary(subContentType);
multi.setBoundary(subBoundary);
boolean nextSubPart = multi.skipPreamble();
while (nextSubPart) {
@@ -344,14 +343,25 @@
* @param contentType The value of the content type header from which to
* extract the boundary value.
*
- * @return The boundary, without any surrounding quotes.
+ * @return The boundary, as a byte array.
*/
- protected String getBoundary(String contentType) {
+ protected byte[] 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");
+ 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;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]