diff --git a/ext/standard/tests/url/parse_url_error_003.phpt b/ext/standard/tests/url/parse_url_error_003.phpt new file mode 100644 index 0000000000000..21fd2b181ce50 --- /dev/null +++ b/ext/standard/tests/url/parse_url_error_003.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test parse_url() function: can not recognize port without scheme +--FILE-- + +--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) "" +} +Done + + + diff --git a/ext/standard/url.c b/ext/standard/url.c index e3d95768fb019..b268e9b0df276 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -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));