Bug #70942 [Com]: parse_url for url without port and scheme, but with port-like string in url
| From: | driezasson at icloud dot com | Date: | Wed, 17 Aug 2016 09:50:26 +0000 |
| Subject: | Bug #70942 [Com]: parse_url for url without port and scheme, but with port-like string in url | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-203343@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70942&edit=1
ID: 70942
Comment by: driezasson at icloud dot com
Reported by: taco at procurios dot nl
Summary: parse_url for url without port and scheme, but with
port-like string in url
Status: Assigned
Type: Bug
Package: URL related
Operating System: linux
PHP Version: 5.6.15
Assigned To: datibbaw
Block user comment: N
Private report: N
New Comment:
Even a URL with a port, but without a scheme doesnât get parsed. E.g.:
'//example.com:80/'.
Expected result:
['host' => 'example.com', 'port' => 80]
Actual result:
false
Previous Comments:
------------------------------------------------------------------------
[2016-02-23 14:55:34] jona at mode dot com
Related To: Bug #71646
------------------------------------------------------------------------
[2016-02-23 12:04:47] cmb@php.net
Related To: Bug #71646
------------------------------------------------------------------------
[2015-11-20 14:46:26] laruence@php.net
@datibbaw, could you have a look into this one? thanks
------------------------------------------------------------------------
[2015-11-20 09:25:00] taco at procurios dot nl
The commit I've mentioned does not introduce this issue. Afaik, this issue is much older, but
was 'masked' by bug #68917. After this bug was fixed
(https://github.com/php/php-src/commit/d7fb52ea20aba5c9ef53dfa57af3b62717c9e9e5#diff-8c81b7e6f1bafce737814315214a5f23)
parse_url no longer returned false for URLs without a scheme, but with a colon.
parse_url assumes that the colon character can only be used for the port subcomponent of a URI, but
it is allowed in the path component too (see: https://tools.ietf.org/html/rfc3986#section-3.3).
The parser should look for a colon character, but not after the first single slash in a URL,
anything after that slash is part of the path, query or fragment.
------------------------------------------------------------------------
[2015-11-19 15:48:51] taco at procurios dot nl
Description:
------------
When a URL without a scheme and port, but with a port-like string (e.g. example.com/foo:1234) is
passed to parse_url(), a port number is returned. This wasn't the case in, at least, PHP 5.6.6
(3v4l.org seems to crash on this code...).
I'm guessing this commit introduced this issue: https://github.com/php/php-src/commit/e49922d3f8060e47f810a24ce48d4e622b493699
Test script:
---------------
var_dump(parse_url('//example.com/foo:1234'))
Expected result:
----------------
Either
bool(false)
or
array(2) {
["host"]=>
string(11) "example.com"
["path"]=>
string(9) "/foo:1234"
}
Actual result:
--------------
array(3) {
["host"]=>
string(11) "example.com"
["port"]=>
int(1234)
["path"]=>
string(9) "/foo:1234"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70942&edit=1