com php-src: Cleanup parse_url() query/fragment handl ing: ext/standard/url.c

From: Date: Tue, 22 Nov 2016 18:24:23 +0000
Subject: com php-src: Cleanup parse_url() query/fragment handl ing: ext/standard/url.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95990@lists.php.net to get a copy of this message
Commit: f0f68c72744a42a1c376a832dd01c012c0929e88 Author: Nikita Popov <nikic@php.net> Fri, 18 Nov 2016 17:00:56 +0100 Parents: 9befad6fc2abe124c1eab80e3dc33e044d3d5db2 Branches: PHP-5.6 PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f0f68c72744a42a1c376a832dd01c012c0929e88 Log: Cleanup parse_url() query/fragment handling The query/fragment handling was pretty convoluted, with many parts being duplicated. Simplify by checking for fragment, then for query, then for path. Changed paths: M ext/standard/url.c Diff: diff --git a/ext/standard/url.c b/ext/standard/url.c index 94b9f20..aa1b031 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -289,51 +289,32 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) just_path: - if ((p = memchr(s, '?', (ue - s)))) { - pp = memchr(s, '#', (ue - s)); - - if (pp && pp < p) { - if (pp - s) { - ret->path = estrndup(s, (pp-s)); - php_replace_controlchars_ex(ret->path, (pp - s)); - } - p = pp; - goto label_parse; - } - - if (p - s) { - ret->path = estrndup(s, (p-s)); - php_replace_controlchars_ex(ret->path, (p - s)); - } - - if (pp) { - if (pp - ++p) { - ret->query = estrndup(p, (pp-p)); - php_replace_controlchars_ex(ret->query, (pp - p)); - } - p = pp; - goto label_parse; - } else if (++p - ue) { - ret->query = estrndup(p, (ue-p)); - php_replace_controlchars_ex(ret->query, (ue - p)); - } - } else if ((p = memchr(s, '#', (ue - s)))) { - if (p - s) { - ret->path = estrndup(s, (p-s)); - php_replace_controlchars_ex(ret->path, (p - s)); + e = ue; + p = memchr(s, '#', (e - s)); + if (p) { + p++; + if (p < e) { + ret->fragment = estrndup(p, (e - p)); + php_replace_controlchars_ex(ret->fragment, (e - p)); } + e = p-1; + } - label_parse: + p = memchr(s, '?', (e - s)); + if (p) { p++; - - if (ue - p) { - ret->fragment = estrndup(p, (ue-p)); - php_replace_controlchars_ex(ret->fragment, (ue - p)); + if (p < e) { + ret->query = estrndup(p, (e - p)); + php_replace_controlchars_ex(ret->query, (e - p)); } - } else { - ret->path = estrndup(s, (ue-s)); - php_replace_controlchars_ex(ret->path, (ue - s)); + e = p-1; } + + if (s < e || s == ue) { + ret->path = estrndup(s, (e - s)); + php_replace_controlchars_ex(ret->path, (e - s)); + } + return ret; } /* }}} */

« previous php.cvs (#95990) next »