Bug #66813 [Opn]: Detect some valid url as invalid in parse_url
| From: | yohgaki@php.net | Date: | Sun, 06 Jul 2014 02:39:18 +0000 |
| Subject: | Bug #66813 [Opn]: Detect some valid url as invalid in parse_url | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186488@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66813&edit=1
ID: 66813
Updated by: yohgaki@php.net
Reported by: fzerorubigd at gmail dot com
Summary: Detect some valid url as invalid in parse_url
Status: Open
Type: Bug
Package: *General Issues
Operating System: Linux x64
PHP Version: 5.5.9
Block user comment: N
Private report: N
New Comment:
To parse it correctly, you need URL encode.
[yohgaki@dev PHP-5.5]$ php -r 'var_dump(rawurlencode(":"));'
string(3) "%3A"
It could be coded to handle ':' in path, but chances are rare unless someone write patch
and send pull request. Please note that there would be good chance that patch is rejected.
Previous Comments:
------------------------------------------------------------------------
[2014-03-06 13:19:36] cmbecker69 at gmx dot de
According to the documentation of parse_url()[1] this is not a
bug:
| Partial URLs are also accepted, parse_url() tries its best to
| parse them correctly.
FWIW, the current behavior is caused by php_url_parse_ex()[2],
which deems the colon to mark the beginning of the port component
and rejects all respective ULRs with up to 5 digits (and nothing
else) after the colon as invalid, because the path component seems
to be missing.
Simple workaround for userland: just prepend any (valid) scheme
component and ignore the scheme element in the result:
var_dump(parse_url("http://example.com/web:1"));
[1] <http://www.php.net/manual/en/function.parse-url.php>
[2] <http://lxr.php.net/xref/PHP_5_5/ext/standard/url.c#php_url_parse_ex>
------------------------------------------------------------------------
[2014-03-03 09:46:07] fzerorubigd at gmail dot com
Description:
------------
This is the result of url like this :
var_dump(parse_url("//example.com/web:o"));
==>
array(2) {
'host' =>
string(11) "example.com"
'path' =>
string(6) "/web:o"
}
but if I replace the :o with :1 the result is false
var_dump(parse_url("//example.com/web:1"));
==>
bool(false)
Also its correct if I use the large integer value :
var_dump(parse_url("//example.com/web:1232323232"));
==>
array(2) {
'host' =>
string(11) "example.com"
'path' =>
string(15) "/web:1232323232"
}
Test script:
---------------
<?php
//Correct:
var_dump(parse_url("//example.com/web:o"));
//Incorrect:
var_dump(parse_url("//example.com/web:1"));
//Correct:
var_dump(parse_url("//example.com/web:1232323232"));
Expected result:
----------------
array(2) {
'host' =>
string(11) "example.com"
'path' =>
string(6) "/web:o"
}
array(2) {
'host' =>
string(11) "example.com"
'path' =>
string(6) "/web:1"
}
array(2) {
'host' =>
string(11) "example.com"
'path' =>
string(15) "/web:1232323232"
}
Actual result:
--------------
array(2) {
'host' =>
string(11) "example.com"
'path' =>
string(6) "/web:o"
}
bool(false)
array(2) {
'host' =>
string(11) "example.com"
'path' =>
string(15) "/web:1232323232"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66813&edit=1