Skip to content

Commit 72d8370

Browse files
PandaLIU-1111cmb69
authored andcommitted
Fix parse_url(): can not recognize port without scheme
Closes phpGH-7844.
1 parent adc8155 commit 72d8370

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ PHP NEWS
6262
. Fixed bug GH-7847 (stripos with large haystack has bad performance).
6363
(ilutov)
6464
. New function memory_reset_peak_usage(). (Patrick Allaert)
65+
. Fixed parse_url(): can not recognize port without scheme. (pandaLIU)
6566

6667
- Zip:
6768
. add ZipArchive::clearError() method
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test parse_url() function: can not recognize port without scheme
3+
--FILE--
4+
<?php
5+
echo "*** Testing parse_url() :can not recognize port without scheme ***\n";
6+
echo 'parse 127.0.0.1:9999?', PHP_EOL;
7+
var_dump(parse_url('127.0.0.1:9999?'));
8+
echo 'parse 127.0.0.1:9999#', PHP_EOL;
9+
var_dump(parse_url('127.0.0.1:9999#'));
10+
?>
11+
--EXPECT--
12+
*** Testing parse_url() :can not recognize port without scheme ***
13+
parse 127.0.0.1:9999?
14+
array(3) {
15+
["host"]=>
16+
string(9) "127.0.0.1"
17+
["port"]=>
18+
int(9999)
19+
["query"]=>
20+
string(0) ""
21+
}
22+
parse 127.0.0.1:9999#
23+
array(3) {
24+
["host"]=>
25+
string(9) "127.0.0.1"
26+
["port"]=>
27+
int(9999)
28+
["fragment"]=>
29+
string(0) ""
30+
}

ext/standard/url.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
150150
p++;
151151
}
152152

153-
if ((p == ue || *p == '/') && (p - e) < 7) {
153+
if ((p == ue || *p == '/' || *p == '?' || *p == '#') && (p - e) < 7) {
154154
goto parse_port;
155155
}
156156

@@ -190,7 +190,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
190190
pp++;
191191
}
192192

193-
if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) {
193+
if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/' || *pp == '?' || *pp == '#')) {
194194
zend_long port;
195195
char *end;
196196
memcpy(port_buf, p, (pp - p));

0 commit comments

Comments
 (0)