mirror of
https://github.com/moparisthebest/curl
synced 2025-01-11 14:08:07 -05:00
urlapi: fix URL encoding when setting a full URL
This commit is contained in:
parent
54c622aa8e
commit
2c20109a9b
17
lib/urlapi.c
17
lib/urlapi.c
@ -851,6 +851,16 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
|
|||||||
if(junkscan(path))
|
if(junkscan(path))
|
||||||
return CURLUE_MALFORMED_INPUT;
|
return CURLUE_MALFORMED_INPUT;
|
||||||
|
|
||||||
|
if((flags & CURLU_URLENCODE) && path[0]) {
|
||||||
|
/* worst case output length is 3x the original! */
|
||||||
|
char *newp = malloc(strlen(path) * 3);
|
||||||
|
if(!newp)
|
||||||
|
return CURLUE_OUT_OF_MEMORY;
|
||||||
|
path_alloced = TRUE;
|
||||||
|
strcpy_url(newp, path, TRUE); /* consider it relative */
|
||||||
|
path = newp;
|
||||||
|
}
|
||||||
|
|
||||||
fragment = strchr(path, '#');
|
fragment = strchr(path, '#');
|
||||||
if(fragment)
|
if(fragment)
|
||||||
*fragment++ = 0;
|
*fragment++ = 0;
|
||||||
@ -865,11 +875,16 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
|
|||||||
else if(!(flags & CURLU_PATH_AS_IS)) {
|
else if(!(flags & CURLU_PATH_AS_IS)) {
|
||||||
/* sanitise paths and remove ../ and ./ sequences according to RFC3986 */
|
/* sanitise paths and remove ../ and ./ sequences according to RFC3986 */
|
||||||
char *newp = Curl_dedotdotify(path);
|
char *newp = Curl_dedotdotify(path);
|
||||||
if(!newp)
|
if(!newp) {
|
||||||
|
if(path_alloced)
|
||||||
|
free(path);
|
||||||
return CURLUE_OUT_OF_MEMORY;
|
return CURLUE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
if(strcmp(newp, path)) {
|
if(strcmp(newp, path)) {
|
||||||
/* if we got a new version */
|
/* if we got a new version */
|
||||||
|
if(path_alloced)
|
||||||
|
free(path);
|
||||||
path = newp;
|
path = newp;
|
||||||
path_alloced = TRUE;
|
path_alloced = TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user