Bug #78997 [Opn->Nab]: PHP parse_url incorrect

From: Date: Thu, 19 Dec 2019 14:37:18 +0000
Subject: Bug #78997 [Opn->Nab]: PHP parse_url incorrect
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224419@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78997&edit=1 ID: 78997 Updated by: geekcom@php.net Reported by: dinhbaouit at gmail dot com Summary: PHP parse_url incorrect -Status: Open +Status: Not a bug Type: Bug Package: *URL Functions Operating System: ubuntu PHP Version: 7.2.26 -Assigned To: +Assigned To: geekcom Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Previous Comments: ------------------------------------------------------------------------ [2019-12-19 14:18:07] geekcom@php.net Hi folk, i did the same test with FQDN and... Test script: --------------- <?php var_dump(parse_url('http://localhost:80?a=1')); ?> Result: ---------------- array(4) { ["scheme"]=> string(4) "http" ["host"]=> string(9) "localhost" ["port"]=> int(80) ["query"]=> string(3) "a=1" } This result is expected . ------------------------------------------------------------------------ [2019-12-19 11:22:44] drtechno at mail dot com The url must be formatted correctly for parse_url to work because it relies on the / symbol as a term separator. $url = 'http://username:password@hostname:9090/path?arg=value#anchor'; $data=parse_url($url); Print_r($data); would return: Array ( [scheme] => http [host] => hostname [port] => 9090 [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor ) $url = 'http://username:password@hostname:9090/path?arg=value#anchor'; var_dump(parse_url($url)); will output the string.length.count with the array: array(8) { ["scheme"]=> string(4) "http" ["host"]=> string(8) "hostname" ["port"]=> int(9090) ["user"]=> string(8) "username" ["pass"]=> string(8) "password" ["path"]=> string(5) "/path" ["query"]=> string(9) "arg=value" ["fragment"]=> string(6) "anchor" } The "host" tag returns a FQDN only, local alias such as localhost will be listed in "scheme" ------------------------------------------------------------------------ [2019-12-19 11:17:02] cmb@php.net I can confirm this behavior[1], but like the documentation[2] states: | Partial URLs are also accepted, parse_url() tries its best to | parse them correctly. So, in my opinion, this is not a bug (and might be duplicate anyway). [1] <https://3v4l.org/h4EMu> [2] <https://www.php.net/parse_url> ------------------------------------------------------------------------ [2019-12-19 09:51:15] dinhbaouit at gmail dot com Description: ------------ In PHP <7.2.26 when using parse_url "host:port?query" the result return incorrect Test script: --------------- <?php var_dump(parse_url("localhost:80?a=1")); ?> Expected result: ---------------- php > var_dump(parse_url("localhost:80?a=1")); array(3) { ["host"]=> string(9) "localhost" ["port"]=> string(2) "80" ["query"]=> string(3) "a=1" } Actual result: -------------- php > var_dump(parse_url("localhost:80?a=1")); array(3) { ["scheme"]=> string(9) "localhost" ["path"]=> string(2) "80" ["query"]=> string(3) "a=1" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78997&edit=1

« previous php.bugs (#224419) next »