Skip to content

Commit

Permalink
Fix issue with nested named parameters.
Browse files Browse the repository at this point in the history
Nested named parameters were not being correctly flattened.

Fixes #2329
  • Loading branch information
markstory committed Dec 2, 2011
1 parent 79d6a85 commit 8b3c72f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
23 changes: 13 additions & 10 deletions 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)
*
Expand All @@ -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 {

/**
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 36 additions & 0 deletions lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php
Expand Up @@ -734,6 +734,42 @@ public function testParseArrayNamedParameters() {
$this->assertEquals($expected, $result);
}

/**
* 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
*
Expand Down

0 comments on commit 8b3c72f

Please sign in to comment.