summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-11-18 17:00:56 +0100
committerNikita Popov <nikic@php.net>2016-11-22 19:24:23 +0100
commitf0f68c72744a42a1c376a832dd01c012c0929e88 (patch)
treef937f071ededb84e72e0f9b6794870d414017d62
parent9befad6fc2abe124c1eab80e3dc33e044d3d5db2 (diff)
downloadphp-git-f0f68c72744a42a1c376a832dd01c012c0929e88.tar.gz
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.
-rw-r--r--ext/standard/url.c61
1 files changed, 21 insertions, 40 deletions
diff --git a/ext/standard/url.c b/ext/standard/url.c
index 94b9f20a16..aa1b0312fe 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;
}
/* }}} */