Permalink
Browse files

Fix issue in Router with prefixes.

Prefixes should not be interpreted as named parameters.
Fixes #2269
  • Loading branch information...
1 parent 0f299a1 commit cb49b242aee96c377e4662326c87b8804d1204a2 @markstory markstory committed Nov 18, 2011
Showing with 17 additions and 2 deletions.
  1. +3 −1 lib/Cake/Routing/Route/CakeRoute.php
  2. +14 −1 lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
@@ -388,6 +388,7 @@ public function match($url) {
}
$namedConfig = Router::namedConfig();
+ $prefixes = Router::prefixes();
$greedyNamed = $namedConfig['greedyNamed'];
$allowedNamedParams = $namedConfig['rules'];
@@ -421,7 +422,8 @@ public function match($url) {
// 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;
@@ -606,7 +606,7 @@ public function testParseNamedParametersWithRules() {
'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(
@@ -666,6 +666,19 @@ public function testParseGreedyNamed() {
}
/**
+ * 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
*
* @return void

0 comments on commit cb49b24

Please sign in to comment.