mirror of
https://github.com/curl/curl.git
synced 2025-09-16 00:52:42 +03:00
urlapi: URL encoding for the URL missed the fragment
Meaning that it would wrongly still store the fragment using spaces instead of %20 if allowing space while also asking for URL encoding. Discovered when playing with trurl. Added test to lib1560 to verify the fix. Closes #10887
This commit is contained in:
parent
4399a532e9
commit
f042e1e75d
11
lib/urlapi.c
11
lib/urlapi.c
|
@ -1131,6 +1131,16 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
|
||||||
fraglen = strlen(fragment);
|
fraglen = strlen(fragment);
|
||||||
if(fraglen > 1) {
|
if(fraglen > 1) {
|
||||||
/* skip the leading '#' in the copy but include the terminating null */
|
/* skip the leading '#' in the copy but include the terminating null */
|
||||||
|
if(flags & CURLU_URLENCODE) {
|
||||||
|
struct dynbuf enc;
|
||||||
|
Curl_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
|
||||||
|
if(urlencode_str(&enc, fragment + 1, fraglen, TRUE, FALSE)) {
|
||||||
|
result = CURLUE_OUT_OF_MEMORY;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
u->fragment = Curl_dyn_ptr(&enc);
|
||||||
|
}
|
||||||
|
else {
|
||||||
u->fragment = Curl_memdup(fragment + 1, fraglen);
|
u->fragment = Curl_memdup(fragment + 1, fraglen);
|
||||||
if(!u->fragment) {
|
if(!u->fragment) {
|
||||||
result = CURLUE_OUT_OF_MEMORY;
|
result = CURLUE_OUT_OF_MEMORY;
|
||||||
|
@ -1143,6 +1153,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
query = strchr(path, '?');
|
query = strchr(path, '?');
|
||||||
if(query && (!fragment || (query < fragment))) {
|
if(query && (!fragment || (query < fragment))) {
|
||||||
|
|
|
@ -141,6 +141,9 @@ struct clearurlcase {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct testcase get_parts_list[] ={
|
static const struct testcase get_parts_list[] ={
|
||||||
|
{"https://user@example.net?hello# space ",
|
||||||
|
"https | user | [12] | [13] | example.net | [15] | / | hello | %20space%20",
|
||||||
|
CURLU_ALLOW_SPACE|CURLU_URLENCODE, 0, CURLUE_OK},
|
||||||
{"https://test%test", "", 0, 0, CURLUE_BAD_HOSTNAME},
|
{"https://test%test", "", 0, 0, CURLUE_BAD_HOSTNAME},
|
||||||
{"https://example.com%252f%40@example.net",
|
{"https://example.com%252f%40@example.net",
|
||||||
"https | example.com%2f@ | [12] | [13] | example.net | [15] | / "
|
"https | example.com%2f@ | [12] | [13] | example.net | [15] | / "
|
||||||
|
|
Loading…
Reference in New Issue
Block a user