Bug #78997 [Com]: PHP parse_url incorrect
| From: | drtechno at mail dot com | Date: | Thu, 19 Dec 2019 11:22:44 +0000 |
| Subject: | Bug #78997 [Com]: PHP parse_url incorrect | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-224407@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
Comment by: drtechno at mail dot com
Reported by: dinhbaouit at gmail dot com
Summary: PHP parse_url incorrect
Status: Open
Type: Bug
Package: *URL Functions
Operating System: ubuntu
PHP Version: 7.2.26
Block user comment: N
Private report: N
New Comment:
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"
Previous Comments:
------------------------------------------------------------------------
[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