From 2108d6983f4343a25a6ba0ce758fe938e6c7c99f Mon Sep 17 00:00:00 2001 From: Andy Postnikov Date: Sat, 17 Sep 2022 22:50:21 +0200 Subject: [PATCH] Revert "Fix parse_url(): can not recognize port without scheme" This reverts commit 72d83709d9524945c93012f7bbb222e412df485a. Closes GH-9569 --- NEWS | 4 +++ .../tests/url/parse_url_basic_011.phpt | 30 +++++++++++++++---- ext/standard/url.c | 4 +-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 2db467fc57b..0d0cbe484e8 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,10 @@ PHP NEWS . Fixed GH-9584 (Avoid memory corruption when not unregistering custom session handler). (ilutov) +- Standard: + . Revert "Fixed parse_url(): can not recognize port without scheme." + (andypost) + 15 Sep 2022, PHP 8.2.0RC2 - Core: diff --git a/ext/standard/tests/url/parse_url_basic_011.phpt b/ext/standard/tests/url/parse_url_basic_011.phpt index 90e42d5b3f1..d0352995979 100644 --- a/ext/standard/tests/url/parse_url_basic_011.phpt +++ b/ext/standard/tests/url/parse_url_basic_011.phpt @@ -7,24 +7,42 @@ 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#')); +echo 'parse internal:#feeding', PHP_EOL; +var_dump(parse_url('internal:#feeding')); +echo 'parse magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C', PHP_EOL; +var_dump(parse_url('magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C')); ?> --EXPECT-- *** Testing parse_url() :can not recognize port without scheme *** parse 127.0.0.1:9999? array(3) { - ["host"]=> + ["scheme"]=> string(9) "127.0.0.1" - ["port"]=> - int(9999) + ["path"]=> + string(4) "9999" ["query"]=> string(0) "" } parse 127.0.0.1:9999# array(3) { - ["host"]=> + ["scheme"]=> string(9) "127.0.0.1" - ["port"]=> - int(9999) + ["path"]=> + string(4) "9999" ["fragment"]=> string(0) "" } +parse internal:#feeding +array(2) { + ["scheme"]=> + string(8) "internal" + ["fragment"]=> + string(7) "feeding" +} +parse magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C +array(2) { + ["scheme"]=> + string(6) "magnet" + ["query"]=> + string(44) "xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C" +} diff --git a/ext/standard/url.c b/ext/standard/url.c index b268e9b0df2..e3d95768fb0 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 == '?' || *p == '#') && (p - e) < 7) { + if ((p == ue || *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 == '/' || *pp == '?' || *pp == '#')) { + if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) { zend_long port; char *end; memcpy(port_buf, p, (pp - p));