Skip to content

Commit

Permalink
Merge pull request #1377 from ravage84/fix-for-3318
Browse files Browse the repository at this point in the history
Trim off webroot/index.php when determining base and url.

Trimming off index.php from url and webroot/index.php from base url allows the correct values to be created when a path contains index.php in it.

Fixes #3318
  • Loading branch information
markstory committed Jul 2, 2013
2 parents 9754789 + f930a50 commit 9a08aea
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 47 deletions.
17 changes: 16 additions & 1 deletion lib/Cake/Network/CakeRequest.php
Expand Up @@ -257,15 +257,25 @@ protected function _url() {
list($uri) = explode('?', $uri, 2);
}
if (empty($uri) || $uri === '/' || $uri === '//' || $uri === '/index.php') {
return '/';
$uri = '/';
}
$endsWithIndex = '/webroot/index.php';
$endsWithLength = strlen($endsWithIndex);
if (strlen($uri) >= $endsWithLength && substr_compare($uri, $endsWithIndex, -$endsWithLength, $endsWithLength) === 0) {
$uri = '/';
}
return $uri;
}

/**
* Returns a base URL and sets the proper webroot
*
* If CakePHP is called with index.php in the URL even though
* URL Rewriting is activated (and thus not needed) it swallows
* the unnecessary part from $base to prevent issue #3318.
*
* @return string Base URL
* @link https://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3318
*/
protected function _base() {
$dir = $webroot = null;
Expand All @@ -283,6 +293,10 @@ protected function _base() {
if (!$baseUrl) {
$base = dirname(env('PHP_SELF'));

$indexPos = strpos($base, '/webroot/index.php');
if ($indexPos !== false) {
$base = substr($base, 0, $indexPos) . '/webroot';
}
if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = dirname($base);
}
Expand All @@ -295,6 +309,7 @@ protected function _base() {
}
$base = implode('/', array_map('rawurlencode', explode('/', $base)));
$this->webroot = $base . '/';

return $this->base = $base;
}

Expand Down

0 comments on commit 9a08aea

Please sign in to comment.