urlapi: allow URLs to not have userauth (hostname)

Verified in test 1560

Fixes #22279
Reported-by: Bill Mill
Closes #22313
This commit is contained in:
Daniel Stenberg 2026-07-13 19:13:45 +02:00
parent 4176aba5e4
commit 33dc64fd0e
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 30 additions and 12 deletions

View file

@ -965,22 +965,30 @@ static CURLUcode parse_scheme(const char *url, CURLU *u, char *schemebuf,
const char *schemep = NULL;
if(schemelen) {
int i = 0;
int num_slashes = 0;
const char *p = &url[schemelen + 1];
while((*p == '/') && (i < 4)) {
p++;
i++;
if(!Curl_get_scheme(schemebuf) && !(flags & CURLU_NON_SUPPORT_SCHEME))
return CURLUE_UNSUPPORTED_SCHEME;
if(!ISSLASH(*p))
/* less than one */
return CURLUE_BAD_SLASHES;
if((flags & CURLU_NO_AUTHORITY)) {
while(ISSLASH(*p) && (num_slashes < 2)) {
p++;
num_slashes++;
}
}
else {
while(ISSLASH(*p) && (num_slashes < 4)) {
p++;
num_slashes++;
}
if(num_slashes > 3)
return CURLUE_BAD_SLASHES;
}
schemep = schemebuf;
if(!Curl_get_scheme(schemep) &&
!(flags & CURLU_NON_SUPPORT_SCHEME))
return CURLUE_UNSUPPORTED_SCHEME;
if((i < 1) || (i > 3))
/* less than one or more than three slashes */
return CURLUE_BAD_SLASHES;
*hostpp = p; /* hostname starts here */
}
else {

View file

@ -153,6 +153,16 @@ struct clearurlcase {
};
static const struct testcase get_parts_list[] = {
/* non-supported URL without hostname */
{"weird:///path",
"weird | [11] | [12] | [13] | | [15] | /path | [16] | [17]",
CURLU_NON_SUPPORT_SCHEME|CURLU_NO_AUTHORITY, 0, CURLUE_OK},
/* non-supported URL without hostname, using path with multiple leading
slashes */
{"weird:////path",
"weird | [11] | [12] | [13] | | [15] | //path | [16] | [17]",
CURLU_NON_SUPPORT_SCHEME|CURLU_NO_AUTHORITY, 0, CURLUE_OK},
/* RFC 4291 IPv4-Mapped IPv6 Addresses */
{"https://[0:0:0:0:0:FFFF:129.144.52.38]:1234",
"https | [11] | [12] | [13] | [::ffff:129.144.52.38] | 1234 "