]> granicus.if.org Git - curl/commitdiff
curl -F: fix multiple file upload with custom type
authorDaniel Stenberg <daniel@haxx.se>
Fri, 16 Dec 2011 10:43:25 +0000 (11:43 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 16 Dec 2011 10:43:25 +0000 (11:43 +0100)
Test case 1315 was added to verify this functionality. When passing in
multiple files to a single -F, the parser would get all confused if one
of the specified files had a custom type= assigned.

Reported by: Colin Hogben

src/tool_formparse.c
tests/data/Makefile.am

index 5d6263e5cdc053dd61e58c8000598d9af46b2d61..ff2210ac8baa8acdf6ddddebc328315721bda2d7 100644 (file)
@@ -73,9 +73,6 @@
  *
  ***************************************************************************/
 
-#define FORM_FILE_SEPARATOR ','
-#define FORM_TYPE_SEPARATOR ';'
-
 int formparse(struct Configurable *config,
               const char *input,
               struct curl_httppost **httppost,
@@ -120,8 +117,8 @@ int formparse(struct Configurable *config,
         char *ptr;
         char *filename = NULL;
 
-        sep = strchr(contp, FORM_TYPE_SEPARATOR);
-        sep2 = strchr(contp, FORM_FILE_SEPARATOR);
+        sep = strchr(contp, ';');
+        sep2 = strchr(contp, ',');
 
         /* pick the closest */
         if(sep2 && (sep2 < sep)) {
@@ -133,16 +130,13 @@ int formparse(struct Configurable *config,
         type = NULL;
 
         if(sep) {
-
-          /* if we got here on a comma, don't do much */
-          if(FORM_FILE_SEPARATOR == *sep)
-            ptr = NULL;
-          else
-            ptr = sep+1;
+          bool semicolon = (';' == *sep);
 
           *sep = '\0'; /* terminate file name at separator */
 
-          while(ptr && (FORM_FILE_SEPARATOR!= *ptr)) {
+          ptr = sep+1; /* point to the text following the separator */
+
+          while(semicolon && ptr && (','!= *ptr)) {
 
             /* pass all white spaces */
             while(ISSPACE(*ptr))
@@ -168,13 +162,17 @@ int formparse(struct Configurable *config,
                  specified and if not we simply assume that it is text that
                  the user wants included in the type and include that too up
                  to the next zero or semicolon. */
-              if((*sep==';') && !checkprefix(";filename=", sep)) {
-                sep2 = strchr(sep+1, ';');
-                if(sep2)
-                  sep = sep2;
-                else
-                  sep = sep + strlen(sep); /* point to end of string */
+              if(*sep==';') {
+                if(!checkprefix(";filename=", sep)) {
+                  sep2 = strchr(sep+1, ';');
+                  if(sep2)
+                    sep = sep2;
+                  else
+                    sep = sep + strlen(sep); /* point to end of string */
+                }
               }
+              else
+                semicolon = FALSE;
 
               if(*sep) {
                 *sep = '\0'; /* zero terminate type string */
@@ -186,9 +184,9 @@ int formparse(struct Configurable *config,
             }
             else if(checkprefix("filename=", ptr)) {
               filename = &ptr[9];
-              ptr = strchr(filename, FORM_TYPE_SEPARATOR);
+              ptr = strchr(filename, ';');
               if(!ptr) {
-                ptr = strchr(filename, FORM_FILE_SEPARATOR);
+                ptr = strchr(filename, ',');
               }
               if(ptr) {
                 *ptr = '\0'; /* zero terminate */
@@ -199,20 +197,10 @@ int formparse(struct Configurable *config,
               /* confusion, bail out of loop */
               break;
           }
-          /* find the following comma */
-          if(ptr)
-            sep = strchr(ptr, FORM_FILE_SEPARATOR);
-          else
-            sep = NULL;
-        }
-        else {
-          sep = strchr(contp, FORM_FILE_SEPARATOR);
-        }
-        if(sep) {
-          /* the next file name starts here */
-          *sep = '\0';
-          sep++;
+
+          sep = ptr;
         }
+
         /* if type == NULL curl_formadd takes care of the problem */
 
         if(!AddMultiFiles(contp, type, filename, &multi_start,
index 93faca212f20748ef445ee020e312d3e87bd6d7b..5bb3725d84237a0d57c8e75ac78debc1b3b09ce0 100644 (file)
@@ -81,7 +81,7 @@ test1208 test1209 test1210 test1211 \
 test1220 \
 test1300 test1301 test1302 test1303 test1304 test1305  \
 test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
-test1314 \
+test1314 test1315 \
 test2000 test2001 test2002 test2003 test2004
 
 EXTRA_DIST = $(TESTCASES) DISABLED