Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue in Router with prefixes.

Prefixes should not be interpreted as named parameters.
Fixes #2269
  • Loading branch information...
commit cb49b242aee96c377e4662326c87b8804d1204a2 1 parent 0f299a1
@markstory markstory authored
View
4 lib/Cake/Routing/Route/CakeRoute.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;
View
15 lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.