Permalink
Browse files

Fix missing directory in dispatcher with rewrite off.

When re-writing is disabled, and the deployment directory
contains either 'app' or 'webroot' the computed path was
incorrect.

Fixes #2330
  • Loading branch information...
markstory committed Dec 3, 2011
1 parent ce49fab commit 3b270926efbb5c0bd6e00db843d6b19ed5da80e4
Showing with 27 additions and 2 deletions.
  1. +2 −2 cake/dispatcher.php
  2. +25 −0 cake/tests/cases/dispatcher.test.php
View
@@ -363,10 +363,10 @@ function baseUrl() {
$docRootContainsWebroot = strpos($docRoot, $dir . '/' . $webroot);
if (!empty($base) || !$docRootContainsWebroot) {
- if (strpos($this->webroot, $dir) === false) {
+ if (strpos($this->webroot, '/' . $dir . '/') === false) {
$this->webroot .= $dir . '/' ;
}
- if (strpos($this->webroot, $webroot) === false) {
+ if (strpos($this->webroot, '/' . $webroot . '/') === false) {
$this->webroot .= $webroot . '/';
}
}
@@ -1207,6 +1207,31 @@ function testBaseUrlAndWebrootWithBaseUrl() {
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);
}
+/**
+ * Check that a sub-directory containing app|webroot doesn't get mishandled when re-writing is off.
+ *
+ * @return void
+ */
+ function testBaseUrlWithAppAndWebrootInDirname() {
+ Configure::write('App.baseUrl', '/approval/index.php');
+ $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
+ $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/approval/index.php';
+ $Dispatcher =& new Dispatcher();
+ $result = $Dispatcher->baseUrl();
+
+ $this->assertEqual('/approval/index.php', $result);
+ $this->assertEqual('/approval/app/webroot/', $Dispatcher->webroot);
+
+ Configure::write('App.baseUrl', '/webrootable/index.php');
+ $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
+ $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/webrootable/index.php';
+ $Dispatcher =& new Dispatcher();
+ $result = $Dispatcher->baseUrl();
+
+ $this->assertEqual('/webrootable/index.php', $result);
+ $this->assertEqual('/webrootable/app/webroot/', $Dispatcher->webroot);
+ }
+
/**
* test baseUrl with no rewrite and using the top level index.php.
*

0 comments on commit 3b27092

Please sign in to comment.