|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-03-03 09:46 UTC] 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"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 08:00:01 2025 UTC |
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>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.