Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit eefb2e81fab0340369fec5b9478518ba83bccfae 1 parent ef1da31
Mark Story markstory authored
7 lib/Cake/Routing/Route/CakeRoute.php
View
@@ -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']);
}
5 lib/Cake/Routing/Router.php
View
@@ -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;
}
}
10 lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
View
@@ -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);
}
/**
4 lib/Cake/Test/Case/Routing/RouterTest.php
View
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.