diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 0c007d1a4..78b787fe1 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -388,6 +388,7 @@ class CakeRoute { } $namedConfig = Router::namedConfig(); + $prefixes = Router::prefixes(); $greedyNamed = $namedConfig['greedyNamed']; $allowedNamedParams = $namedConfig['rules']; @@ -421,7 +422,8 @@ class CakeRoute { // pull out named params if named params are greedy or a rule exists. if ( ($greedyNamed || isset($allowedNamedParams[$key])) && - ($value !== false && $value !== null) + ($value !== false && $value !== null) && + (!in_array($key, $prefixes)) ) { $named[$key] = $value; continue; diff --git a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php index 605d1eff8..77f6eed9a 100644 --- a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php +++ b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php @@ -606,7 +606,7 @@ class CakeRouteTest extends CakeTestCase { 'fish' => 'trout' ) ); - $this->assertEquals($expected, $result, 'Fish should be parsed, as action == index'); + $this->assertEquals($expected, $result, 'Fizz should be parsed, as controller == comments|other'); $result = $route->parse('/comments/index/wibble:spin/fish:trout/fizz:buzz'); $expected = array( @@ -665,6 +665,19 @@ class CakeRouteTest extends CakeTestCase { $this->assertEquals($expected, $result, 'Greedy named grabs everything, rules are followed'); } +/** + * Having greedNamed enabled should not capture routing.prefixes. + * + * @return void + */ + public function testMatchGreedyNamedExcludesPrefixes() { + Configure::write('Routing.prefixes', array('admin')); + Router::reload(); + + $route = new CakeRoute('/sales/*', array('controller' => 'sales', 'action' => 'index')); + $this->assertFalse($route->match(array('controller' => 'sales', 'action' => 'index', 'admin' => 1)), 'Greedy named consume routing prefixes.'); + } + /** * test that parsing array format named parameters works *