Skip to content

Commit

Permalink
Handle REQUEST_URI with domain names properly.
Browse files Browse the repository at this point in the history
Don't depend on parse_url() as it fails with corrupted urls.  Instead
use FULL_BASE_URL to prepare an absolute path.

Fixes #3270
  • Loading branch information
markstory committed Oct 14, 2012
1 parent 513851d commit 59f8402
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Cake/Network/CakeRequest.php
Expand Up @@ -229,8 +229,10 @@ protected function _processGet() {
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'])) {
Expand Down
24 changes: 24 additions & 0 deletions lib/Cake/Test/Case/Network/CakeRequestTest.php
Expand Up @@ -1646,6 +1646,30 @@ public static function environmentGenerator() {
'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(
Expand Down

0 comments on commit 59f8402

Please sign in to comment.