From: Ilia Alshanetsky Date: Thu, 7 Nov 2002 15:41:32 +0000 (+0000) Subject: parse_url can now correctly parse mailto:, zlib: (old zlib wrapper) and X-Git-Tag: php-4.3.0RC1~204 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8645f5c200b43267fdab45c4c4785894703109fb;p=php parse_url can now correctly parse mailto:, zlib: (old zlib wrapper) and simular. Thanks to Wez Furlong for noticing the problem. --- diff --git a/ext/standard/url.c b/ext/standard/url.c index 4227070060..781b0ca5b5 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -94,19 +94,49 @@ PHPAPI php_url *php_url_parse(char *str) ue = s + length; /* parse scheme */ - if ((e = strchr(s, ':')) && *(e+1) == '/' && (e-s)) { - ret->scheme = estrndup(s, (e-s)); - php_replace_controlchars(ret->scheme); - - if (*(e+2) == '/') { - s = e + 3; + if ((e = strchr(s, ':')) && (e-s)) { + /* + * certain schemas like mailto: and zlib: may not have any / after them + * this check ensures we support those. + */ + if (*(e+1) != '/') { + /* check if the data we get is a port this allows us to + * correctly parse things like a.com:80 + */ + p = e + 1; + while (isdigit(*p)) { + p++; + } + + if ((*p) == '\0' || *p == '/') { + goto parse_port; + } + + ret->scheme = estrndup(s, (e-s)); + php_replace_controlchars(ret->scheme); + + length -= ++e - s; + s = e; + goto just_path; } else { - s = e + 1; - if (!strncasecmp("file", ret->scheme, sizeof("file"))) { - goto nohost; - } + ret->scheme = estrndup(s, (e-s)); + php_replace_controlchars(ret->scheme); + + if (*(e+2) == '/') { + s = e + 3; + } else { + s = e + 1; + if (!strncasecmp("file", ret->scheme, sizeof("file"))) { + goto nohost; + } else { + length -= ++e - s; + s = e; + goto just_path; + } + } } } else if (e) { /* no scheme, look for port */ + parse_port: p = e + 1; pp = p; @@ -123,13 +153,15 @@ PHPAPI php_url *php_url_parse(char *str) } } else { just_path: - ret->path = estrndup(str, length); + ret->path = estrndup(s, length); php_replace_controlchars(ret->path); return ret; } if (!(e = strchr(s, '/'))) { e = ue; + } else if (e && e == s) { + e = ue; } /* check for login and password */ @@ -145,6 +177,9 @@ PHPAPI php_url *php_url_parse(char *str) ret->pass = estrndup(pp, (p-pp)); php_replace_controlchars(ret->pass); } + } else { + ret->user = estrndup(s, (p-s)); + php_replace_controlchars(ret->user); } s = p + 1;