Bug #54369 [NEW]: parse_url() incorrectly determines the start of query and fragment parts of URL

From: Date: Thu, 24 Mar 2011 14:46:34 +0000
Subject: Bug #54369 [NEW]: parse_url() incorrectly determines the start of query and fragment parts of URL
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-159746@lists.php.net to get a copy of this message
From:             
Operating system: 
PHP version:      Irrelevant
Package:          URL related
Bug Type:         Bug
Bug description:parse_url() incorrectly determines the start of query and fragment parts of URL

Description:
------------
Attached patch fixes the issue.

Test script:
---------------
$url = 'http://www.example.com#fra/gment';
echo $url . "\n";
var_dump(parse_url($url));

$url = 'http://www.example.com?p=1/param';
echo $url . "\n";
var_dump(parse_url($url));

// No host, should return false
$url = 'http://#fra/gment';
echo $url . "\n";
var_dump(parse_url($url));

// No host, should return false
$url = 'http://?p=1/param';
echo $url . "\n";
var_dump(parse_url($url));

Expected result:
----------------
http://www.example.com#fra/gment
array(3) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(15) "www.example.com"
  ["fragment"]=>
  string(9) "fra/gment"
}
http://www.example.com?p=1/param
array(3) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(15) "www.example.com"
  ["query"]=>
  string(9) "p=1/param"
}
http://#fra/gment
bool(false)
http://?p=1/param
bool(false)

Actual result:
--------------
http://www.example.com#fra/gment
array(3) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(19) "www.example.com#fra"
  ["path"]=>
  string(6) "/gment"
}
http://www.example.com?p=1/param
array(3) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(19) "www.example.com?p=1"
  ["path"]=>
  string(6) "/param"
}
http://#fra/gment
array(3) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(4) "#fra"
  ["path"]=>
  string(6) "/gment"
}
http://?p=1/param
array(3) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(4) "?p=1"
  ["path"]=>
  string(6) "/param"
}

-- 
Edit bug report at http://bugs.php.net/bug.php?id=54369&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=54369&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=54369&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=54369&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=54369&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54369&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=54369&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=54369&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=54369&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=54369&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=54369&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=54369&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=54369&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=54369&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=54369&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54369&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54369&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=54369&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=54369&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=54369&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=54369&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=54369&r=mysqlcfg



Thread (15 messages)

« previous php.bugs (#159746) next »