Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue with nested named parameters.

Nested named parameters were not being correctly flattened.

Fixes #2329
  • Loading branch information...
commit 8b3c72f7c1c7c53ed22e6ec8565cbce7bc275894 1 parent 79d6a85
@markstory markstory authored
View
23 lib/Cake/Routing/Route/CakeRoute.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 {
View
36 lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.