Skip to content

Commit d7fb52e

Browse files
committed
Fixed bug #68917 (parse_url fails on some partial urls)
1 parent e892f53 commit d7fb52e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2015, PHP 5.5.24
44

5+
- Core:
6+
. Fixed bug #68917 (parse_url fails on some partial urls). (Wei Dai)
57

68
19 Mar 2015, PHP 5.5.23
79

ext/standard/tests/url/bug68917.phpt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #68917 (parse_url fails on some partial urls)
3+
--FILE--
4+
<?php
5+
print_r(parse_url('//example.org:81/hi?a=b#c=d'));
6+
print_r(parse_url('//example.org/hi?a=b#c=d'));
7+
?>
8+
--EXPECT--
9+
Array
10+
(
11+
[host] => example.org
12+
[port] => 81
13+
[path] => /hi
14+
[query] => a=b
15+
[fragment] => c=d
16+
)
17+
Array
18+
(
19+
[host] => example.org
20+
[path] => /hi
21+
[query] => a=b
22+
[fragment] => c=d
23+
)

ext/standard/url.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
192192
port = strtol(port_buf, NULL, 10);
193193
if (port > 0 && port <= 65535) {
194194
ret->port = (unsigned short) port;
195+
if (*s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
196+
s += 2;
197+
}
195198
} else {
196199
STR_FREE(ret->scheme);
197200
efree(ret);
@@ -201,12 +204,12 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
201204
STR_FREE(ret->scheme);
202205
efree(ret);
203206
return NULL;
204-
} else if (*s == '/' && *(s+1) == '/') { /* relative-scheme URL */
207+
} else if (*s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
205208
s += 2;
206209
} else {
207210
goto just_path;
208211
}
209-
} else if (*s == '/' && *(s+1) == '/') { /* relative-scheme URL */
212+
} else if (*s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
210213
s += 2;
211214
} else {
212215
just_path:

0 commit comments

Comments
 (0)