Fix parse_url(): can not recognize port without scheme

Closes GH-7844.
This commit is contained in:
pandaLIU 2021-12-30 14:25:34 +01:00 committed by Christoph M. Becker
parent adc8155119
commit 72d83709d9
No known key found for this signature in database
GPG Key ID: D66C9593118BCCB6
3 changed files with 33 additions and 2 deletions

1
NEWS
View File

@ -62,6 +62,7 @@ PHP NEWS
. Fixed bug GH-7847 (stripos with large haystack has bad performance).
(ilutov)
. New function memory_reset_peak_usage(). (Patrick Allaert)
. Fixed parse_url(): can not recognize port without scheme. (pandaLIU)
- Zip:
. add ZipArchive::clearError() method

View File

@ -0,0 +1,30 @@
--TEST--
Test parse_url() function: can not recognize port without scheme
--FILE--
<?php
echo "*** Testing parse_url() :can not recognize port without scheme ***\n";
echo 'parse 127.0.0.1:9999?', PHP_EOL;
var_dump(parse_url('127.0.0.1:9999?'));
echo 'parse 127.0.0.1:9999#', PHP_EOL;
var_dump(parse_url('127.0.0.1:9999#'));
?>
--EXPECT--
*** Testing parse_url() :can not recognize port without scheme ***
parse 127.0.0.1:9999?
array(3) {
["host"]=>
string(9) "127.0.0.1"
["port"]=>
int(9999)
["query"]=>
string(0) ""
}
parse 127.0.0.1:9999#
array(3) {
["host"]=>
string(9) "127.0.0.1"
["port"]=>
int(9999)
["fragment"]=>
string(0) ""
}

View File

@ -150,7 +150,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
p++;
}
if ((p == ue || *p == '/') && (p - e) < 7) {
if ((p == ue || *p == '/' || *p == '?' || *p == '#') && (p - e) < 7) {
goto parse_port;
}
@ -190,7 +190,7 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
pp++;
}
if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) {
if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/' || *pp == '?' || *pp == '#')) {
zend_long port;
char *end;
memcpy(port_buf, p, (pp - p));