diff --git a/cake/libs/router.php b/cake/libs/router.php index 84a24abf5..3707a56d7 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -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; diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index da062342b..08739db83 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -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