Permalink
Browse files

Fix for #3318

Fixes https://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3318

It seems fixing this in the htaccess file(s) isn't going to work even though a url rewriting based solution was more clean. On the plus side this works for any web server.
If a url is called with "index.php" in it then the CakeRequest swallows this part and fixes the path. Any linked url from the requested page will have a clean url. Thus after following one of these urls this problem is gone anyway.

Some code docblock improvements to CakeRequestTest.php
Added test case for fix
Also now you can call just index.php even if you have url rewriting enabled
  • Loading branch information...
1 parent 1d18a4f commit f930a50805a03ae36b928421873d361f51f2703d @ravage84 ravage84 committed Jun 26, 2013
Showing with 139 additions and 47 deletions.
  1. +16 −1 lib/Cake/Network/CakeRequest.php
  2. +123 −46 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -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;
@@ -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);
}
@@ -295,6 +309,7 @@ protected function _base() {
}
$base = implode('/', array_map('rawurlencode', explode('/', $base)));
$this->webroot = $base . '/';
+
return $this->base = $base;
}
Oops, something went wrong.

0 comments on commit f930a50

Please sign in to comment.