Permalink
Browse files

Fix issue with nested named parameters.

Nested named parameters were not being correctly flattened.

Fixes #2329
  • Loading branch information...
1 parent 79d6a85 commit 8b3c72f7c1c7c53ed22e6ec8565cbce7bc275894 @markstory markstory committed Dec 2, 2011
Showing with 49 additions and 10 deletions.
  1. +13 −10 lib/Cake/Routing/Route/CakeRoute.php
  2. +36 −0 lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
@@ -1,13 +1,5 @@
<?php
/**
- * A single Route used by the Router to connect requests to
- * parameter maps.
- *
- * Not normally created as a standalone. Use Router::connect() to create
- * Routes for your application.
- *
- * PHP5
- *
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -16,10 +8,20 @@
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
- * @package Cake.Routing.Route
* @since CakePHP(tm) v 1.3
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+App::uses('Set', 'Utility');
+
+/**
+ * A single Route used by the Router to connect requests to
+ * parameter maps.
+ *
+ * Not normally created as a standalone. Use Router::connect() to create
+ * Routes for your application.
+ *
+ * @package Cake.Routing.Route
+ */
class CakeRoute {
/**
@@ -475,7 +477,8 @@ protected function _writeUrl($params) {
$named = array();
foreach ($params['named'] as $key => $value) {
if (is_array($value)) {
- foreach ($value as $namedKey => $namedValue) {
+ $flat = Set::flatten($value, '][');
+ foreach ($flat as $namedKey => $namedValue) {
$named[] = $key . "[$namedKey]" . $separator . rawurlencode($namedValue);
}
} else {
@@ -735,6 +735,42 @@ public function testParseArrayNamedParameters() {
}
/**
+ * Test that match can handle array named parameters
+ *
+ * @return void
+ */
+ public function testMatchNamedParametersArray() {
+ $route = new CakeRoute('/:controller/:action/*');
+
+ $url = array(
+ 'controller' => 'posts',
+ 'action' => 'index',
+ 'filter' => array(
+ 'one',
+ 'model' => 'value'
+ )
+ );
+ $result = $route->match($url);
+ $expected = '/posts/index/filter[0]:one/filter[model]:value';
+ $this->assertEquals($expected, $result);
+
+ $url = array(
+ 'controller' => 'posts',
+ 'action' => 'index',
+ 'filter' => array(
+ 'one',
+ 'model' => array(
+ 'two',
+ 'order' => 'field'
+ )
+ )
+ );
+ $result = $route->match($url);
+ $expected = '/posts/index/filter[0]:one/filter[model][0]:two/filter[model][order]:field';
+ $this->assertEquals($expected, $result);
+ }
+
+/**
* test restructuring args with pass key
*
* @return void

0 comments on commit 8b3c72f

Please sign in to comment.