Bug #66813 [Com]: Detect some valid url as invalid in parse_url

From: Date: Thu, 06 Mar 2014 13:19:37 +0000
Subject: Bug #66813 [Com]: Detect some valid url as invalid in parse_url
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184570@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 Comment by: cmbecker69 at gmx dot de 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: 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> Previous Comments: ------------------------------------------------------------------------ [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 (#184570) next »