curl / Mailing Lists / curl-library / Single Mail

curl-library

Change Curl_is_absolute_url to allow URI without authority

From: Aron Bergman via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 1 May 2019 20:27:40 +0200

Hi,
I have a suggestion for the Curl_is_absolute_url function.

If I have understood it correctly, the function will determine whether the given URL is an absolute URI or a relative reference according to section 4.2 and 4.3 in RFC 3986. It will also try to be user-friendly by allowing the URI to start with a authority (host + port) which isn’t prefixed with a double slash by making the assumption that a scheme is always followed by a double slash (and then the authority), but a URI doesn’t have to include a authority (even if all of the currently implemented protocols do).

I propose to change the check for a slash to instead check that the char isn’t a number.

This will make the function better adhere to the standard URI syntax while still allowing it to be user-friendly. This won’t make the function completely standard compliant since the standard allows a colon after the host and then a zero-length port number, though I’ve never seen a URI being used that way.

diff --git a/lib/urlapi.c b/lib/urlapi.c
index 0eb06d24d..fc7925bea 100644
--- a/lib/urlapi.c
+++ b/lib/urlapi.c
@@ -238,7 +238,7 @@ bool Curl_is_absolute_url(const char *url, char *buf, size_t buflen)
 #endif
   for(i = 0; i < buflen && url[i]; ++i) {
     char s = url[i];
- if((s == ':') && (url[i + 1] == '/')) {
+ if((s == ':') && (!ISDIGIT(url[i + 1]))) {
       if(buf)
         buf[i] = 0;
       return TRUE;

What do you think?

Regards,
Aron Bergman

P.S. Is there any preferred line-length for mail?
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-05-01