mirror of
https://github.com/curl/curl.git
synced 2026-08-26 21:54:19 +03:00
urlapi: improved return codes
- add CURLUE_BACKSLASH that can be returned when a backslash was used where a forward one probably was intended. - make CURLUE_NO_HOST higher priority than port number errors for URLs without hostname. Like in "http://::1" - shortened some URL parser error strings Extend test 1560 to verify. Reported-by: kit-ty-kate on github Fixes #22337 Closes #22408
This commit is contained in:
parent
c7328740ec
commit
573a6ec16b
8 changed files with 54 additions and 27 deletions
|
|
@ -452,34 +452,34 @@ const char *curl_url_strerror(CURLUcode error)
|
|||
return "An unknown part ID was passed to a URL API function";
|
||||
|
||||
case CURLUE_NO_SCHEME:
|
||||
return "No scheme part in the URL";
|
||||
return "No scheme present";
|
||||
|
||||
case CURLUE_NO_USER:
|
||||
return "No user part in the URL";
|
||||
return "No user present";
|
||||
|
||||
case CURLUE_NO_PASSWORD:
|
||||
return "No password part in the URL";
|
||||
return "No password present";
|
||||
|
||||
case CURLUE_NO_OPTIONS:
|
||||
return "No options part in the URL";
|
||||
return "No options present";
|
||||
|
||||
case CURLUE_NO_HOST:
|
||||
return "No host part in the URL";
|
||||
return "No host present";
|
||||
|
||||
case CURLUE_NO_PORT:
|
||||
return "No port part in the URL";
|
||||
return "No port number present";
|
||||
|
||||
case CURLUE_NO_QUERY:
|
||||
return "No query part in the URL";
|
||||
return "No query present";
|
||||
|
||||
case CURLUE_NO_FRAGMENT:
|
||||
return "No fragment part in the URL";
|
||||
return "No fragment present";
|
||||
|
||||
case CURLUE_NO_ZONEID:
|
||||
return "No zoneid part in the URL";
|
||||
return "No zoneid present";
|
||||
|
||||
case CURLUE_BAD_LOGIN:
|
||||
return "Bad login part";
|
||||
return "Bad login";
|
||||
|
||||
case CURLUE_BAD_IPV6:
|
||||
return "Bad IPv6 address";
|
||||
|
|
@ -517,6 +517,9 @@ const char *curl_url_strerror(CURLUcode error)
|
|||
case CURLUE_TOO_LARGE:
|
||||
return "A value or data field is larger than allowed";
|
||||
|
||||
case CURLUE_BACKSLASH:
|
||||
return "Found a backslash where a forward slash was expected";
|
||||
|
||||
case CURLUE_LAST:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
16
lib/urlapi.c
16
lib/urlapi.c
|
|
@ -382,6 +382,7 @@ UNITTEST CURLUcode parse_port(struct Curl_URL *u, struct dynbuf *host,
|
|||
if(portptr) {
|
||||
curl_off_t port;
|
||||
size_t keep = portptr - hostname;
|
||||
int rc;
|
||||
|
||||
/* Browser behavior adaptation. If there is a colon with no digits after,
|
||||
cut off the name there which makes us ignore the colon and use the
|
||||
|
|
@ -393,8 +394,14 @@ UNITTEST CURLUcode parse_port(struct Curl_URL *u, struct dynbuf *host,
|
|||
portptr++;
|
||||
if(!*portptr)
|
||||
return has_scheme ? CURLUE_OK : CURLUE_BAD_PORT_NUMBER;
|
||||
|
||||
if(curlx_str_number(&portptr, &port, 0xffff) || *portptr)
|
||||
if(*portptr == '\\')
|
||||
return CURLUE_BACKSLASH;
|
||||
rc = curlx_str_number(&portptr, &port, 0xffff);
|
||||
if(rc)
|
||||
return CURLUE_BAD_PORT_NUMBER;
|
||||
else if(*portptr == '\\')
|
||||
return CURLUE_BACKSLASH;
|
||||
else if(*portptr)
|
||||
return CURLUE_BAD_PORT_NUMBER;
|
||||
|
||||
u->portnum = (uint16_t)port;
|
||||
|
|
@ -666,12 +673,11 @@ static CURLUcode parse_authority(struct Curl_URL *u,
|
|||
}
|
||||
|
||||
uc = parse_port(u, host, has_scheme);
|
||||
if(uc)
|
||||
return uc;
|
||||
|
||||
if(!curlx_dyn_len(host))
|
||||
/* this makes no-host errors override port number problems */
|
||||
uc = CURLUE_NO_HOST;
|
||||
else
|
||||
if(!uc)
|
||||
uc = urldecode_host(host);
|
||||
if(uc)
|
||||
return uc;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue