]> granicus.if.org Git - curl/commitdiff
cmdline: make -F type= accept ;charset=
authorDaniel Stenberg <daniel@haxx.se>
Fri, 20 Aug 2010 22:21:24 +0000 (00:21 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 20 Aug 2010 22:21:24 +0000 (00:21 +0200)
The -F option allows some custom parameters within the given string, and
those strings are separated with semicolons. You can for example specify
"name=daniel;type=text/plain" to set content-type for the
field. However, the use of semicolons like that made it not work fine if
you specified one within the content-type, like for:
"name=daniel;type=text/plain;charset=UTF-8"
... as the second one would be seen as a separator and "charset" is no
parameter curl knows anything about so it was just silently discarded.

The new logic now checks if the semicolon and following keyword looks
like a parameter it knows about and if it isn't it is assumed to be
meant to be used within the content-type string itself.

I modified test case 186 to verify that this works as intended.

Reported by: Larry Stone
Bug: http://curl.haxx.se/bug/view.cgi?id=3048988

src/main.c
tests/data/test186

index e5279aa4ffce895e0f38648a9d61fa660f2d9149..093f6bed4e876b68e061a96322cb1f4edd41487e 100644 (file)
@@ -1202,9 +1202,17 @@ static int formparse(struct Configurable *config,
                 FreeMultiInfo (multi_start);
                 return 2; /* illegal content-type syntax! */
               }
+
               /* now point beyond the content-type specifier */
               sep = (char *)type + strlen(major)+strlen(minor)+1;
 
+              /* there's a semicolon following - we check if it is a filename
+                 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==';') && !curlx_strnequal(";filname=", sep, 9))
+                sep = strchr(sep+1, ';');
+
               if(*sep) {
                 *sep=0; /* zero terminate type string */
 
index cbb36a8a2c3a257c19df706213d26b7ef53b7822..5a1b7b9ac3ab4252c91d1e10528918d770e6f64e 100644 (file)
@@ -21,7 +21,7 @@ http
 HTTP RFC1867-type formposting with types on text fields
  </name>
  <command>
-http://%HOSTIP:%HTTPPORT/we/want/186 -F "name=daniel;type=moo/foo" -F "html= <body>hello</body>;type=text/html"
+http://%HOSTIP:%HTTPPORT/we/want/186 -F "name=daniel;type=moo/foo" -F "html= <body>hello</body>;type=text/html;charset=verymoo"
 </command>
 # We create this file before the command is invoked!
 </client>
@@ -36,7 +36,7 @@ POST /we/want/186 HTTP/1.1
 User-Agent: curl/7.12.2-CVS (i686-pc-linux-gnu) libcurl/7.12.2-CVS OpenSSL/0.9.7d zlib/1.2.1.1 c-ares/1.2.0 libidn/0.5.2\r
 Host: %HOSTIP:%HTTPPORT\r
 Accept: */*\r
-Content-Length: 305\r
+Content-Length: 321\r
 Expect: 100-continue\r
 Content-Type: multipart/form-data; boundary=----------------------------212d9006ceb5\r
 \r
@@ -47,7 +47,7 @@ Content-Type: moo/foo
 daniel\r
 ------------------------------212d9006ceb5\r
 Content-Disposition: form-data; name="html"\r
-Content-Type: text/html\r
+Content-Type: text/html;charset=verymoo\r
 \r
  <body>hello</body>\r
 ------------------------------212d9006ceb5--\r