Fixing Router::normalize() so that a url containing the base param more than once, which is passed into normalize() multiple times does not get url segments removed. Fixes #6338 and #5978

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8236 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2009-07-20 13:18:38 +00:00
parent 74fd4849ba
commit d2245fd514
2 changed files with 18 additions and 2 deletions

View file

@ -1200,7 +1200,7 @@ class Router extends Object {
$paths = Router::getPaths();
if (!empty($paths['base']) && stristr($url, $paths['base'])) {
$url = preg_replace('/' . preg_quote($paths['base'], '/') . '/', '', $url, 1);
$url = preg_replace('/^' . preg_quote($paths['base'], '/') . '/', '', $url, 1);
}
$url = '/' . $url;

View file

@ -299,7 +299,7 @@ class RouterTest extends CakeTestCase {
$result = Router::normalize('/recipe/recipes/add');
$this->assertEqual($result, '/recipe/recipes/add');
Router::setRequestInfo(array(array(), array('base' => 'us')));
Router::setRequestInfo(array(array(), array('base' => '/us')));
$result = Router::normalize('/us/users/logout/');
$this->assertEqual($result, '/users/logout');
@ -309,6 +309,22 @@ class RouterTest extends CakeTestCase {
$result = Router::normalize('/cake_12/users/logout/');
$this->assertEqual($result, '/users/logout');
Router::reload();
$_back = Configure::read('App.baseUrl');
Configure::write('App.baseUrl', '/');
Router::setRequestInfo(array(array(), array('base' => '/')));
$result = Router::normalize('users/login');
$this->assertEqual($result, '/users/login');
Configure::write('App.baseUrl', $_back);
Router::reload();
Router::setRequestInfo(array(array(), array('base' => 'beer')));
$result = Router::normalize('beer/admin/beers_tags/add');
$this->assertEqual($result, '/admin/beers_tags/add');
$result = Router::normalize('/admin/beers_tags/add');
$this->assertEqual($result, '/admin/beers_tags/add');
}
/**
* testUrlGeneration method