Bug #66813 [Opn->Csd]: Detect some valid url as invalid in parse_url

From: Date: Fri, 01 May 2015 17:42:51 +0000
Subject: Bug #66813 [Opn->Csd]: Detect some valid url as invalid in parse_url
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192439@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: cmb@php.net Reported by: fzerorubigd at gmail dot com Summary: Detect some valid url as invalid in parse_url -Status: Open +Status: Closed Type: Bug Package: *General Issues Operating System: Linux x64 PHP Version: 5.5.9 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Thank you for your bug report. This issue has already been fixed in the latest released version of PHP, which you can download at http://www.php.net/downloads.php fixed in 5.5.24 and 5.6.8 Previous Comments: ------------------------------------------------------------------------ [2015-01-27 00:16:58] requinix@php.net Related To: Bug #68917 ------------------------------------------------------------------------ [2014-07-06 02:39:18] yohgaki@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#192439) next »