Skip to content

Commit 9befad6

Browse files
committed
Cleanup parse_url() gotos
Simplify some unnecessarily complicated code. In particular the length updates are unnecessary (length is only used at the very start) and we're goto'ing around a bit too much.
1 parent 3e45385 commit 9befad6

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

ext/standard/url.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
122122
if (*(e + 1) == '\0') { /* only scheme is available */
123123
ret->scheme = estrndup(s, (e - s));
124124
php_replace_controlchars_ex(ret->scheme, (e - s));
125-
goto end;
125+
return ret;
126126
}
127127

128128
/*
@@ -145,8 +145,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
145145
ret->scheme = estrndup(s, (e-s));
146146
php_replace_controlchars_ex(ret->scheme, (e - s));
147147

148-
length -= ++e - s;
149-
s = e;
148+
s = e + 1;
150149
goto just_path;
151150
} else {
152151
ret->scheme = estrndup(s, (e-s));
@@ -162,18 +161,12 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
162161
if (*(e + 5) == ':') {
163162
s = e + 4;
164163
}
165-
goto nohost;
164+
goto just_path;
166165
}
167166
}
168167
} else {
169-
if (!strncasecmp("file", ret->scheme, sizeof("file"))) {
170-
s = e + 1;
171-
goto nohost;
172-
} else {
173-
length -= ++e - s;
174-
s = e;
175-
goto just_path;
176-
}
168+
s = e + 1;
169+
goto just_path;
177170
}
178171
}
179172
} else if (e) { /* no scheme; starts with colon: look for port */
@@ -212,9 +205,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
212205
} else if (*s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
213206
s += 2;
214207
} else {
215-
just_path:
216-
ue = s + length;
217-
goto nohost;
208+
goto just_path;
218209
}
219210

220211
e = s + strcspn(s, "/?#");
@@ -296,7 +287,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
296287

297288
s = e;
298289

299-
nohost:
290+
just_path:
300291

301292
if ((p = memchr(s, '?', (ue - s)))) {
302293
pp = memchr(s, '#', (ue - s));
@@ -343,7 +334,6 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
343334
ret->path = estrndup(s, (ue-s));
344335
php_replace_controlchars_ex(ret->path, (ue - s));
345336
}
346-
end:
347337
return ret;
348338
}
349339
/* }}} */

0 commit comments

Comments
 (0)