1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-15 22:15:13 -05:00

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, int formparse(struct Configurable *config,
const char *input, const char *input,
struct curl_httppost **httppost, struct curl_httppost **httppost,
@ -120,8 +117,8 @@ int formparse(struct Configurable *config,
char *ptr; char *ptr;
char *filename = NULL; char *filename = NULL;
sep = strchr(contp, FORM_TYPE_SEPARATOR); sep = strchr(contp, ';');
sep2 = strchr(contp, FORM_FILE_SEPARATOR); sep2 = strchr(contp, ',');
/* pick the closest */ /* pick the closest */
if(sep2 && (sep2 < sep)) { if(sep2 && (sep2 < sep)) {
@ -133,16 +130,13 @@ int formparse(struct Configurable *config,
type = NULL; type = NULL;
if(sep) { if(sep) {
bool semicolon = (';' == *sep);
/* if we got here on a comma, don't do much */
if(FORM_FILE_SEPARATOR == *sep)
ptr = NULL;
else
ptr = sep+1;
*sep = '\0'; /* terminate file name at separator */ *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 */ /* pass all white spaces */
while(ISSPACE(*ptr)) while(ISSPACE(*ptr))
@ -168,13 +162,17 @@ int formparse(struct Configurable *config,
specified and if not we simply assume that it is text that specified and if not we simply assume that it is text that
the user wants included in the type and include that too up the user wants included in the type and include that too up
to the next zero or semicolon. */ to the next zero or semicolon. */
if((*sep==';') && !checkprefix(";filename=", sep)) { if(*sep==';') {
sep2 = strchr(sep+1, ';'); if(!checkprefix(";filename=", sep)) {
if(sep2) sep2 = strchr(sep+1, ';');
sep = sep2; if(sep2)
else sep = sep2;
sep = sep + strlen(sep); /* point to end of string */ else
sep = sep + strlen(sep); /* point to end of string */
}
} }
else
semicolon = FALSE;
if(*sep) { if(*sep) {
*sep = '\0'; /* zero terminate type string */ *sep = '\0'; /* zero terminate type string */
@ -186,9 +184,9 @@ int formparse(struct Configurable *config,
} }
else if(checkprefix("filename=", ptr)) { else if(checkprefix("filename=", ptr)) {
filename = &ptr[9]; filename = &ptr[9];
ptr = strchr(filename, FORM_TYPE_SEPARATOR); ptr = strchr(filename, ';');
if(!ptr) { if(!ptr) {
ptr = strchr(filename, FORM_FILE_SEPARATOR); ptr = strchr(filename, ',');
} }
if(ptr) { if(ptr) {
*ptr = '\0'; /* zero terminate */ *ptr = '\0'; /* zero terminate */
@ -199,20 +197,10 @@ int formparse(struct Configurable *config,
/* confusion, bail out of loop */ /* confusion, bail out of loop */
break; break;
} }
/* find the following comma */
if(ptr) sep = 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++;
} }
/* if type == NULL curl_formadd takes care of the problem */ /* if type == NULL curl_formadd takes care of the problem */
if(!AddMultiFiles(contp, type, filename, &multi_start, if(!AddMultiFiles(contp, type, filename, &multi_start,

View File

@ -81,7 +81,7 @@ test1208 test1209 test1210 test1211 \
test1220 \ test1220 \
test1300 test1301 test1302 test1303 test1304 test1305 \ test1300 test1301 test1302 test1303 test1304 test1305 \
test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \ test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
test1314 \ test1314 test1315 \
test2000 test2001 test2002 test2003 test2004 test2000 test2001 test2002 test2003 test2004
EXTRA_DIST = $(TESTCASES) DISABLED EXTRA_DIST = $(TESTCASES) DISABLED