urlapi: add CURLU_GET_EMPTY for empty queries and fragments

By default the API inhibits empty queries and fragments extracted.
Unless this new flag is set.

This also makes the behavior more consistent: without it set, zero
length queries and fragments are considered not present in the URL. With
the flag set, they are returned as a zero length strings if they were in
fact present in the URL.

This applies when extracting the individual query and fragment
components and for the full URL.

Closes #13396
This commit is contained in:
Daniel Stenberg 2024-04-17 11:39:25 +02:00
parent 5379dbc248
commit 3eac21d86b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 77 additions and 10 deletions

View file

@ -151,6 +151,21 @@ struct clearurlcase {
};
static const struct testcase get_parts_list[] ={
{"https://curl.se/#",
"https | [11] | [12] | [13] | curl.se | [15] | / | [16] | ",
0, CURLU_GET_EMPTY, CURLUE_OK},
{"https://curl.se/?#",
"https | [11] | [12] | [13] | curl.se | [15] | / | | ",
0, CURLU_GET_EMPTY, CURLUE_OK},
{"https://curl.se/?",
"https | [11] | [12] | [13] | curl.se | [15] | / | | [17]",
0, CURLU_GET_EMPTY, CURLUE_OK},
{"https://curl.se/?",
"https | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
0, 0, CURLUE_OK},
{"https://curl.se/?#",
"https | [11] | [12] | [13] | curl.se | [15] | / | [16] | [17]",
0, 0, CURLUE_OK},
{"https://curl.se/# ",
"https | [11] | [12] | [13] | curl.se | [15] | / | [16] | %20%20",
CURLU_URLENCODE|CURLU_ALLOW_SPACE, 0, CURLUE_OK},
@ -508,6 +523,9 @@ static const struct testcase get_parts_list[] ={
};
static const struct urltestcase get_url_list[] = {
{"http://user@example.com?#",
"http://user@example.com/?#",
0, CURLU_GET_EMPTY, CURLUE_OK},
/* WHATWG disgrees, it wants "https:/0.0.0.0/" */
{"https://0x.0x.0", "https://0x.0x.0/", 0, 0, CURLUE_OK},
@ -781,6 +799,18 @@ static int checkurl(const char *org, const char *url, const char *out)
3. Extract all components (not URL)
*/
static const struct setgetcase setget_parts_list[] = {
{"https://example.com/",
"query=\"\",",
"https | [11] | [12] | [13] | example.com | [15] | / | | [17]",
0, 0, CURLU_GET_EMPTY, CURLUE_OK},
{"https://example.com/",
"fragment=\"\",",
"https | [11] | [12] | [13] | example.com | [15] | / | [16] | ",
0, 0, CURLU_GET_EMPTY, CURLUE_OK},
{"https://example.com/",
"query=\"\",",
"https | [11] | [12] | [13] | example.com | [15] | / | [16] | [17]",
0, 0, 0, CURLUE_OK},
{"https://example.com",
"path=get,",
"https | [11] | [12] | [13] | example.com | [15] | /get | [16] | [17]",