Bug #54031 [NEW]: parse_url failing for certain partial URLs
| From: | andreas at blixt dot org | Date: | Wed, 16 Feb 2011 16:24:32 +0000 |
| Subject: | Bug #54031 [NEW]: parse_url failing for certain partial URLs | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-158811@lists.php.net to get a copy of this message | ||
From:
Operating system: Mac OS X 10.6.6
PHP version: 5.3.5
Package: URL related
Bug Type: Bug
Bug description:parse_url failing for certain partial URLs
Description:
------------
The parse_url function fails to parse any partial URL with a colon followed
by a
slash ":/" in it. It should have no problems parsing them though, since
it's
easy to determine whether a URL is partial or not (any string that does not
start with a scheme [ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )] and
then
an
authority [which in the case of URLs starts with two slashes "//"] cannot
be a
URL; see RFC 3986).
In the case of partial URLs, it would be expected that parse_url acts as if
"http://tld" was prepended to the input string (without
returning the
"scheme"
or "host" parts, obviously).
The reason I'm filing this as a bug is because a script which uses a
trusted
source of a partial URL (such as $_SERVER['REQUEST_URI'] in most
environments)
and relies on parse_url will fail as soon as the visitor adds ":/"
somewhere in
the path.
My current workaround is to check whether the URL is partial ($url{0} ==
'/' is
sufficient in most cases) and if so, prepend a scheme and authority to it
before
passing it to parse_url.
Test script:
---------------
$ php -r 'var_dump(parse_url("/?x=:/"));' # Fails
$ php -r 'var_dump(parse_url("/?x=:)"));' # Works
Expected result:
----------------
$ php -r 'var_dump(parse_url("/?x=:/"));'
array(2) {
["path"]=>
string(1) "/"
["query"]=>
string(4) "x=:/"
}
$ php -r 'var_dump(parse_url("/?x=:)"));'
array(2) {
["path"]=>
string(1) "/"
["query"]=>
string(4) "x=:)"
}
Actual result:
--------------
$ php -r 'var_dump(parse_url("/?x=:/"));'
bool(false)
$ php -r 'var_dump(parse_url("/?x=:)"));'
array(2) {
["path"]=>
string(1) "/"
["query"]=>
string(4) "x=:)"
}
--
Edit bug report at http://bugs.php.net/bug.php?id=54031&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54031&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54031&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54031&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=54031&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54031&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=54031&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=54031&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=54031&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=54031&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=54031&r=support
Expected behavior: http://bugs.php.net/fix.php?id=54031&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=54031&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=54031&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=54031&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54031&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54031&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=54031&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=54031&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=54031&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=54031&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=54031&r=mysqlcfg