Handle REQUEST_URI with domain names properly.

Don't depend on parse_url() as it fails with corrupted urls.  Instead
use FULL_BASE_URL to prepare an absolute path.

Fixes #3270
This commit is contained in:
mark_story 2012-10-14 11:58:07 -04:00
parent 513851d1c1
commit 59f84024e5
2 changed files with 27 additions and 1 deletions

View file

@ -229,8 +229,10 @@ class CakeRequest implements ArrayAccess {
protected function _url() {
if (!empty($_SERVER['PATH_INFO'])) {
return $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
} elseif (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '://') === false) {
$uri = $_SERVER['REQUEST_URI'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$uri = substr($_SERVER['REQUEST_URI'], strlen(FULL_BASE_URL));
} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {

View file

@ -1646,6 +1646,30 @@ class CakeRequestTest extends CakeTestCase {
'webroot' => '/',
),
),
array(
'Apache - w/rewrite, document root set above top level cake dir, request root, absolute REQUEST_URI',
array(
'App' => array(
'base' => false,
'baseUrl' => false,
'dir' => 'app',
'webroot' => 'webroot'
),
'SERVER' => array(
'SERVER_NAME' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
'REQUEST_URI' => FULL_BASE_URL . '/site/posts/index',
'SCRIPT_NAME' => '/site/app/webroot/index.php',
'PHP_SELF' => '/site/app/webroot/index.php',
),
),
array(
'url' => 'posts/index',
'base' => '/site',
'webroot' => '/site/',
),
),
array(
'Nginx - w/rewrite, document root set to webroot, request root, no PATH_INFO',
array(