commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r572918 - in /commons/proper/fileupload/trunk/src: java/org/apache/commons/fileupload/FileUploadBase.java java/org/apache/commons/fileupload/ParameterParser.java test/org/apache/commons/fileupload/ParameterParserTest.java
Date Wed, 05 Sep 2007 09:21:20 GMT
Author: bayard
Date: Wed Sep  5 02:21:19 2007
New Revision: 572918

URL: http://svn.apache.org/viewvc?rev=572918&view=rev
Log:
Applying the patch from FILEUPLOAD-139 so that comma separators are supported (as per rfc1867)
as well as semi-colons

Modified:
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
    commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ParameterParserTest.java

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java?rev=572918&r1=572917&r2=572918&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
Wed Sep  5 02:21:19 2007
@@ -391,7 +391,7 @@
         ParameterParser parser = new ParameterParser();
         parser.setLowerCaseNames(true);
         // Parameter parser can handle null input
-        Map params = parser.parse(contentType, ';');
+        Map params = parser.parse(contentType, new char[] {';', ','});
         String boundaryStr = (String) params.get("boundary");
 
         if (boundaryStr == null) {

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java?rev=572918&r1=572917&r2=572918&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ParameterParser.java
Wed Sep  5 02:21:19 2007
@@ -216,6 +216,36 @@
 
     /**
      * Extracts a map of name/value pairs from the given string. Names are
+     * expected to be unique. Multiple separators may be specified and 
+     * the earliest found in the input string is used.
+     *
+     * @param str the string that contains a sequence of name/value pairs
+     * @param separator the name/value pairs separators
+     *
+     * @return a map of name/value pairs
+     */
+    public Map parse(final String str, char[] separators) {
+        if (separators == null || separators.length == 0) {
+            return new HashMap();
+        }
+        char separator = separators[0];
+        if (str != null) {
+            int idx = str.length();
+            for (int i=0; i<separators.length; i++) {
+                int tmp = str.indexOf(separators[i]);
+                if (tmp != -1) {
+                    if (tmp < idx) {
+                        idx = tmp;
+                        separator = separators[i];
+                    }
+                }
+            }
+        }
+        return parse(str, separator);
+    }
+
+    /**
+     * Extracts a map of name/value pairs from the given string. Names are
      * expected to be unique.
      *
      * @param str the string that contains a sequence of name/value pairs

Modified: commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ParameterParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ParameterParserTest.java?rev=572918&r1=572917&r2=572918&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ParameterParserTest.java
(original)
+++ commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ParameterParserTest.java
Wed Sep  5 02:21:19 2007
@@ -60,6 +60,12 @@
         assertEquals("stuff; stuff", params.get("test2"));
         assertEquals("\"stuff", params.get("test3"));
 
+        params = parser.parse(s, new char[] { ',', ';' });
+        assertEquals(null, params.get("test"));
+        assertEquals("stuff", params.get("test1"));
+        assertEquals("stuff; stuff", params.get("test2"));
+        assertEquals("\"stuff", params.get("test3"));
+
         s = "  test  , test1=stuff   ,  , test2=, test3, ";
         params = parser.parse(s, ',');
         assertEquals(null, params.get("test"));
@@ -102,5 +108,22 @@
         assertEquals(2, params.size());
         assertEquals("stuff\\\\", params.get("param"));
         assertNull(params.get("anotherparam"));
+    }
+
+    // See: http://issues.apache.org/jira/browse/FILEUPLOAD-139
+    public void testFileUpload139() 
+    {
+        ParameterParser parser = new ParameterParser();
+        String s = "Content-type: multipart/form-data , boundary=AaB03x";
+        Map params = parser.parse(s, new char[] { ',', ';' });
+        assertEquals("AaB03x", params.get("boundary"));
+
+        s = "Content-type: multipart/form-data, boundary=AaB03x";
+        params = parser.parse(s, new char[] { ';', ',' });
+        assertEquals("AaB03x", params.get("boundary"));
+
+        s = "Content-type: multipart/mixed, boundary=BbC04y";
+        params = parser.parse(s, new char[] { ',', ';' });
+        assertEquals("BbC04y", params.get("boundary"));
     }
 }



Mime
View raw message