mirror of
https://github.com/moparisthebest/curl
synced 2025-01-11 05:58:01 -05:00
urlapi: URL encode a '+' in the query part
... when asked to with CURLU_URLENCODE. Extended test 1560 to verify. Reported-by: Dietmar Hauser Fixes #6086 Closes #6087
This commit is contained in:
parent
3862c37b63
commit
b7ea3d2c22
27
lib/urlapi.c
27
lib/urlapi.c
@ -1387,28 +1387,17 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
|
|||||||
if(urlencode) {
|
if(urlencode) {
|
||||||
const unsigned char *i;
|
const unsigned char *i;
|
||||||
char *o;
|
char *o;
|
||||||
bool free_part = FALSE;
|
|
||||||
char *enc = malloc(nalloc * 3 + 1); /* for worst case! */
|
char *enc = malloc(nalloc * 3 + 1); /* for worst case! */
|
||||||
if(!enc)
|
if(!enc)
|
||||||
return CURLUE_OUT_OF_MEMORY;
|
return CURLUE_OUT_OF_MEMORY;
|
||||||
if(plusencode) {
|
|
||||||
/* space to plus */
|
|
||||||
i = (const unsigned char *)part;
|
|
||||||
for(o = enc; *i; ++o, ++i)
|
|
||||||
*o = (*i == ' ') ? '+' : *i;
|
|
||||||
*o = 0; /* null-terminate */
|
|
||||||
part = strdup(enc);
|
|
||||||
if(!part) {
|
|
||||||
free(enc);
|
|
||||||
return CURLUE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
free_part = TRUE;
|
|
||||||
}
|
|
||||||
for(i = (const unsigned char *)part, o = enc; *i; i++) {
|
for(i = (const unsigned char *)part, o = enc; *i; i++) {
|
||||||
if(Curl_isunreserved(*i) ||
|
if((*i == ' ') && plusencode) {
|
||||||
((*i == '/') && urlskipslash) ||
|
*o = '+';
|
||||||
((*i == '=') && equalsencode) ||
|
o++;
|
||||||
((*i == '+') && plusencode)) {
|
}
|
||||||
|
else if(Curl_isunreserved(*i) ||
|
||||||
|
((*i == '/') && urlskipslash) ||
|
||||||
|
((*i == '=') && equalsencode)) {
|
||||||
if((*i == '=') && equalsencode)
|
if((*i == '=') && equalsencode)
|
||||||
/* only skip the first equals sign */
|
/* only skip the first equals sign */
|
||||||
equalsencode = FALSE;
|
equalsencode = FALSE;
|
||||||
@ -1422,8 +1411,6 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
|
|||||||
}
|
}
|
||||||
*o = 0; /* null-terminate */
|
*o = 0; /* null-terminate */
|
||||||
newp = enc;
|
newp = enc;
|
||||||
if(free_part)
|
|
||||||
free((char *)part);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -478,6 +478,13 @@ static int checkurl(const char *url, const char *out)
|
|||||||
|
|
||||||
/* !checksrc! disable SPACEBEFORECOMMA 1 */
|
/* !checksrc! disable SPACEBEFORECOMMA 1 */
|
||||||
static struct setcase set_parts_list[] = {
|
static struct setcase set_parts_list[] = {
|
||||||
|
{"https://example.com/",
|
||||||
|
"query=Al2cO3tDkcDZ3EWE5Lh+LX8TPHs,", /* contains '+' */
|
||||||
|
"https://example.com/?Al2cO3tDkcDZ3EWE5Lh%2bLX8TPHs",
|
||||||
|
CURLU_URLDECODE, /* decode on get */
|
||||||
|
CURLU_URLENCODE, /* encode on set */
|
||||||
|
CURLUE_OK, CURLUE_OK},
|
||||||
|
|
||||||
{"https://example.com/",
|
{"https://example.com/",
|
||||||
/* Set a 41 bytes scheme. That's too long so the old scheme remains set. */
|
/* Set a 41 bytes scheme. That's too long so the old scheme remains set. */
|
||||||
"scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc,",
|
"scheme=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc,",
|
||||||
|
Loading…
Reference in New Issue
Block a user