curl -F: fix multiple file upload with custom type

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
This commit is contained in:
Daniel Stenberg 2011-12-16 11:43:25 +01:00
parent 9b185aac43
commit 7b8590d1f5
2 changed files with 22 additions and 34 deletions

View 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,

View 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