Skip to content

Commit

Permalink
Fixing issue where webroot paths would be incorrect when using a virt…
Browse files Browse the repository at this point in the history
…ual host setup and no mod_rewrite. An additional app/webroot would be appended. Incorrect tests updated. Fixes #259
  • Loading branch information
markstory committed Jan 27, 2010
1 parent fc30405 commit 2d81d25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 10 additions & 7 deletions cake/dispatcher.php
Expand Up @@ -367,21 +367,24 @@ function baseUrl() {
$this->webroot = $base .'/';
return $base;
}
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);

if ($base === DS || $base === '.') {
$base = '';
}
$this->webroot = $base .'/';
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);

if ($base === DS || $base === '.') {
$base = '';
}
$this->webroot = $base .'/';

if (!empty($base)) {
if (strpos($this->webroot, $dir) === false) {
$this->webroot .= $dir . '/' ;
}
if (strpos($this->webroot, $webroot) === false) {
$this->webroot .= $webroot . '/';
}
return $base . $file;
}
return $base . $file;
}
/**
* Restructure params in case we're serving a plugin.
Expand Down
14 changes: 7 additions & 7 deletions cake/tests/cases/dispatcher.test.php
Expand Up @@ -1103,7 +1103,7 @@ function testBaseUrlAndWebrootWithBaseUrl() {
$result = $Dispatcher->baseUrl();
$expected = '/index.php';
$this->assertEqual($expected, $result);
$expectedWebroot = '/app/webroot/';
$expectedWebroot = '/';
$this->assertEqual($expectedWebroot, $Dispatcher->webroot);

Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
Expand Down Expand Up @@ -1174,12 +1174,12 @@ function testBaseUrlAndWebrootWithBase() {
*/
function testMissingController() {
$Dispatcher =& new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
Configure::write('App.baseUrl', '/index.php');
$url = 'some_controller/home/param:value/param2:value2';
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = array('missingController', array(array(
'className' => 'SomeControllerController',
'webroot' => '/app/webroot/',
'webroot' => '/',
'url' => 'some_controller/home/param:value/param2:value2',
'base' => '/index.php'
)));
Expand All @@ -1201,7 +1201,7 @@ function testPrivate() {
$expected = array('privateAction', array(array(
'className' => 'SomePagesController',
'action' => '_protected',
'webroot' => '/app/webroot/',
'webroot' => '/',
'url' => 'some_pages/_protected/param:value/param2:value2',
'base' => '/index.php'
)));
Expand All @@ -1215,15 +1215,15 @@ function testPrivate() {
*/
function testMissingAction() {
$Dispatcher =& new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
Configure::write('App.baseUrl', '/index.php');
$url = 'some_pages/home/param:value/param2:value2';

$controller = $Dispatcher->dispatch($url, array('return'=> 1));

$expected = array('missingAction', array(array(
'className' => 'SomePagesController',
'action' => 'home',
'webroot' => '/app/webroot/',
'webroot' => '/',
'url' => '/index.php/some_pages/home/param:value/param2:value2',
'base' => '/index.php'
)));
Expand All @@ -1238,7 +1238,7 @@ function testMissingAction() {
$expected = array('missingAction', array(array(
'className' => 'SomePagesController',
'action' => 'redirect',
'webroot' => '/app/webroot/',
'webroot' => '/',
'url' => '/index.php/some_pages/redirect/param:value/param2:value2',
'base' => '/index.php'
)));
Expand Down

0 comments on commit 2d81d25

Please sign in to comment.