Skip to content

Commit

Permalink
Fix missing directory in dispatcher with rewrite off.
Browse files Browse the repository at this point in the history
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 d4fd1b3 commit 22352a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Network/CakeRequest.php
Expand Up @@ -278,10 +278,10 @@ protected function _base() {
$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 . '/';
}
}
Expand Down
23 changes: 23 additions & 0 deletions lib/Cake/Test/Case/Network/CakeRequestTest.php
Expand Up @@ -1041,6 +1041,29 @@ public function testBaseUrlNoRewriteTopLevelIndex() {
$this->assertEquals('/app/webroot/', $request->webroot);
}

/**
* Check that a sub-directory containing app|webroot doesn't get mishandled when re-writing is off.
*
* @return void
*/
public function testBaseUrlWithAppAndWebrootInDirname() {
Configure::write('App.baseUrl', '/approval/index.php');
$_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
$_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/approval/index.php';

$request = new CakeRequest();
$this->assertEquals('/approval/index.php', $request->base);
$this->assertEquals('/approval/app/webroot/', $request->webroot);

Configure::write('App.baseUrl', '/webrootable/index.php');
$_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
$_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/webrootable/index.php';

$request = new CakeRequest();
$this->assertEquals('/webrootable/index.php', $request->base);
$this->assertEquals('/webrootable/app/webroot/', $request->webroot);
}

/**
* test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
*
Expand Down

0 comments on commit 22352a0

Please sign in to comment.