Skip to content

Commit

Permalink
Fix issue where prefixes mid action would be truncated.
Browse files Browse the repository at this point in the history
If a prefix occured mid action name it would be removed,
corrupting the action name.

Fixes #2831
  • Loading branch information
markstory committed Apr 25, 2012
1 parent ef1da31 commit eefb2e8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/Cake/Routing/Route/CakeRoute.php
Expand Up @@ -478,8 +478,11 @@ public function match($url) {
* @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']);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/Routing/Router.php
Expand Up @@ -893,8 +893,9 @@ protected static function _handleNoRoute($url) {

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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
Expand Up @@ -299,6 +299,16 @@ public function testMatchBasic() {
$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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -1582,6 +1582,10 @@ public function testUrlGenerationWithAutoPrefixes() {
$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);
Expand Down

0 comments on commit eefb2e8

Please sign in to comment.