mirror of
https://github.com/curl/curl.git
synced 2026-08-24 19:13:39 +03:00
Alessandro Vesely helped me improve the --data-urlencode's syntax, parser
and documentation.
This commit is contained in:
parent
cb04619de2
commit
ecfede9b3c
4 changed files with 61 additions and 47 deletions
26
src/main.c
26
src/main.c
|
|
@ -2059,19 +2059,21 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||
*/
|
||||
char *p = strchr(nextarg, '=');
|
||||
long size = 0;
|
||||
size_t nlen;
|
||||
int nlen;
|
||||
char is_file;
|
||||
if(!p)
|
||||
p = strchr(nextarg, '@');
|
||||
if(!p) {
|
||||
warnf(config, "bad use of --data-urlencode\n");
|
||||
return PARAM_BAD_USE;
|
||||
if (p) {
|
||||
nlen = p - nextarg; /* length of the name part */
|
||||
is_file = *p++; /* pass the separator */
|
||||
}
|
||||
nlen = p - nextarg; /* length of the name part */
|
||||
if('@' == *p) {
|
||||
else {
|
||||
nlen = is_file = -1;
|
||||
p = nextarg;
|
||||
}
|
||||
if('@' == is_file) {
|
||||
/* a '@' letter, it means that a file name or - (stdin) follows */
|
||||
|
||||
p++; /* pass the separator */
|
||||
|
||||
if(curlx_strequal("-", p)) {
|
||||
file = stdin;
|
||||
SET_BINMODE(stdin);
|
||||
|
|
@ -2090,7 +2092,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||
fclose(file);
|
||||
}
|
||||
else {
|
||||
GetStr(&postdata, ++p);
|
||||
GetStr(&postdata, p);
|
||||
size = strlen(postdata);
|
||||
}
|
||||
|
||||
|
|
@ -2108,8 +2110,10 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||
char *n = malloc(outlen);
|
||||
if(!n)
|
||||
return PARAM_NO_MEM;
|
||||
|
||||
snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
|
||||
if (nlen > 0) /* only append '=' if we have a name */
|
||||
snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
|
||||
else
|
||||
strcpy(n, enc);
|
||||
curl_free(enc);
|
||||
free(postdata);
|
||||
if(n) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue