Fix issue where prefixes mid action would be truncated.

If a prefix occured mid action name it would be removed,
corrupting the action name.

Fixes #2831
This commit is contained in:
mark_story 2012-04-24 20:48:23 -04:00
parent ef1da3146e
commit eefb2e81fa
4 changed files with 22 additions and 4 deletions

View file

@ -478,8 +478,11 @@ class CakeRoute {
* @return string Composed route string.
*/
protected function _writeUrl($params) {
if (isset($params['prefix'], $params['action'])) {
$params['action'] = str_replace($params['prefix'] . '_', '', $params['action']);
if (isset($params['prefix'])) {
$prefixed = $params['prefix'] . '_';
}
if (isset($prefixed, $params['action']) && strpos($params['action'], $prefixed) === 0) {
$params['action'] = substr($params['action'], strlen($prefixed) * -1);
unset($params['prefix']);
}

View file

@ -893,8 +893,9 @@ class Router {
list($args, $named) = array(Set::filter($args, true), Set::filter($named, true));
foreach (self::$_prefixes as $prefix) {
if (!empty($url[$prefix])) {
$url['action'] = str_replace($prefix . '_', '', $url['action']);
$prefixed = $prefix . '_';
if (!empty($url[$prefix]) && strpos($url['action'], $prefixed) === 0) {
$url['action'] = substr($url['action'], strlen($prefixed) * -1);
break;
}
}

View file

@ -299,6 +299,16 @@ class CakeRouteTest extends CakeTestCase {
$result = $route->match($url);
$expected = '/admin/subscriptions/edit/1';
$this->assertEquals($expected, $result);
$url = array(
'controller' => 'subscribe',
'admin' => true,
'action' => 'edit_admin_e',
1
);
$result = $route->match($url);
$expected = '/admin/subscriptions/edit_admin_e/1';
$this->assertEquals($expected, $result);
}
/**

View file

@ -1582,6 +1582,10 @@ class RouterTest extends CakeTestCase {
$expected = '/protected/images/add';
$this->assertEquals($expected, $result);
$result = Router::url(array('controller' => 'images', 'action' => 'add_protected_test', 'protected' => true));
$expected = '/protected/images/add_protected_test';
$this->assertEquals($expected, $result);
$result = Router::url(array('action' => 'edit', 1));
$expected = '/images/edit/1';
$this->assertEquals($expected, $result);