Skip to content

Commit

Permalink
Fixing issues with / routes, as PATH_INFO doesn't exist.
Browse files Browse the repository at this point in the history
Changing foreach loop for if elseif blocks, and removing use of env().  The values we want will never be anywhere else by _SERVER, so don't incur extra overhead looking places it won't be.
Added tests.
  • Loading branch information
markstory committed Feb 22, 2011
1 parent c5f2919 commit 6426b7e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
22 changes: 11 additions & 11 deletions cake/libs/cake_request.php
Expand Up @@ -187,18 +187,18 @@ protected function _processGet() {
* @return string URI The CakePHP request path that is being accessed.
*/
protected function _url() {
$pathInfo = env('PATH_INFO');
if (!empty($pathInfo)) {
return $pathInfo;
}
foreach (array('PHP_SELF', 'REQUEST_URI', 'HTTP_X_REWRITE_URL', 'argv') as $var) {
if ($uri = env($var)) {
if ($var == 'argv') {
$uri = $url[0];
}
break;
}
if (!empty($_SERVER['PATH_INFO'])) {
return $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
} 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'])) {
$uri = $_SERVER['HTTP_X_REWRITE_URL'];
} elseif ($var = env('argv')) {
$uri = $var[0];
}

$base = $this->base;

if (strpos($uri, $base) === 0) {
Expand Down
58 changes: 53 additions & 5 deletions cake/tests/cases/libs/cake_request.test.php
Expand Up @@ -1172,7 +1172,7 @@ public static function environmentGenerator() {
),
),
array(
'Apache - No rewrite, document root set above top level cake dir, requesting root',
'Apache - No rewrite, document root set above top level cake dir, reques root, no PATH_INFO',
array(
'App' => array(
'base' => false,
Expand All @@ -1184,9 +1184,8 @@ public static function environmentGenerator() {
'SERVER_NAME' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
'REQUEST_URI' => '/site/index.php/',
'REQUEST_URI' => '/site/index.php/',
'SCRIPT_NAME' => '/site/index.php',
'PATH_INFO' => '',
'PHP_SELF' => '/site/index.php/',
),
),
Expand Down Expand Up @@ -1223,7 +1222,56 @@ public static function environmentGenerator() {
'base' => '/site/index.php',
'webroot' => '/site/app/webroot/',
),
)
),
array(
'Apache - w/rewrite, document root set above top level cake dir, request root, no PATH_INFO',
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' => '/site/',
'SCRIPT_NAME' => '/site/app/webroot/index.php',
'PHP_SELF' => '/site/app/webroot/index.php',
),
),
array(
'url' => '',
'base' => '/site',
'webroot' => '/site/',
),
),
array(
'Apache - w/rewrite, document root above top level cake dir, request root, no PATH_INFO/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',
'SCRIPT_NAME' => '/site/app/webroot/index.php',
'PHP_SELF' => '/site/app/webroot/index.php',
'PATH_INFO' => null,
'REQUEST_URI' => null,
),
),
array(
'url' => '',
'base' => '/site',
'webroot' => '/site/',
),
),
);
}

Expand All @@ -1239,7 +1287,7 @@ public function testEnvironmentDetection($name, $env, $expected) {
$request = new CakeRequest();
$this->assertEquals($expected['url'], $request->url, "url error");
$this->assertEquals($expected['base'], $request->base, "base error");
$this->assertEquals($expected['webroot'],$request->webroot, "webroot error");
$this->assertEquals($expected['webroot'], $request->webroot, "webroot error");
if (isset($expected['urlParams'])) {
$this->assertEqual($_GET, $expected['urlParams'], "GET param mismatch");
}
Expand Down

0 comments on commit 6426b7e

Please sign in to comment.