Skip to content

Commit db287b2

Browse files
jhdxrkrakjoe
authored andcommitted
fix bug #74780 parse_url() borken when query string contains colon
1 parent b3bd379 commit db287b2

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2017 PHP 7.0.22
44

5-
5+
- Core:
6+
. Fixed bug #74780 (parse_url() borken when query string contains colon).
7+
(jhdxr)
68

79
06 Jul 2017 PHP 7.0.21
810

ext/standard/tests/url/bug74780.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #74780 parse_url() borks when query string contains colon
3+
--FILE--
4+
<?php
5+
var_dump(
6+
parse_url('//php.net/path?query=1:2'),
7+
parse_url('//php.net/path.php?query=a:b'),
8+
parse_url('//[email protected]/path?query=1:2')
9+
);
10+
11+
?>
12+
--EXPECT--
13+
array(3) {
14+
["host"]=>
15+
string(7) "php.net"
16+
["path"]=>
17+
string(5) "/path"
18+
["query"]=>
19+
string(9) "query=1:2"
20+
}
21+
array(3) {
22+
["host"]=>
23+
string(7) "php.net"
24+
["path"]=>
25+
string(9) "/path.php"
26+
["query"]=>
27+
string(9) "query=a:b"
28+
}
29+
array(4) {
30+
["host"]=>
31+
string(7) "php.net"
32+
["user"]=>
33+
string(8) "username"
34+
["path"]=>
35+
string(5) "/path"
36+
["query"]=>
37+
string(9) "query=1:2"
38+
}

ext/standard/url.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
112112
if (!isalpha(*p) && !isdigit(*p) && *p != '+' && *p != '.' && *p != '-') {
113113
if (e + 1 < ue && e < s + strcspn(s, "?#")) {
114114
goto parse_port;
115+
} else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
116+
s += 2;
117+
e = 0;
118+
goto parse_host;
115119
} else {
116120
goto just_path;
117121
}
@@ -208,6 +212,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
208212
goto just_path;
209213
}
210214

215+
parse_host:
211216
/* Binary-safe strcspn(s, "/?#") */
212217
e = ue;
213218
if ((p = memchr(s, '/', e - s))) {

0 commit comments

Comments
 (0)