Skip to content

Commit

Permalink
url encode nested named parameters in unmatched routes
Browse files Browse the repository at this point in the history
reference: #2988
and 3103323
  • Loading branch information
AD7six committed Oct 5, 2012
1 parent 52f2060 commit fa6defe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Routing/Router.php
Expand Up @@ -945,9 +945,9 @@ protected static function _handleNoRoute($url) {
if (!empty($named)) {
foreach ($named as $name => $value) {
if (is_array($value)) {
$flattend = Hash::flatten($value, '][');
$flattend = Hash::flatten($value, '%5D%5B');
foreach ($flattend as $namedKey => $namedValue) {
$output .= '/' . $name . "[$namedKey]" . self::$_namedConfig['separator'] . rawurlencode($namedValue);
$output .= '/' . $name . "%5B{$namedKey}%5D" . self::$_namedConfig['separator'] . rawurlencode($namedValue);
}
} else {
$output .= '/' . $name . self::$_namedConfig['separator'] . rawurlencode($value);
Expand Down
10 changes: 5 additions & 5 deletions lib/Cake/Test/Case/Routing/RouterTest.php
Expand Up @@ -484,7 +484,7 @@ public function testArrayNamedParameters() {
$result = Router::url(array('controller' => 'tests', 'pages' => array(
1, 2, 3
)));
$expected = '/tests/index/pages[0]:1/pages[1]:2/pages[2]:3';
$expected = '/tests/index/pages%5B0%5D:1/pages%5B1%5D:2/pages%5B2%5D:3';
$this->assertEquals($expected, $result);

$result = Router::url(array('controller' => 'tests',
Expand All @@ -496,7 +496,7 @@ public function testArrayNamedParameters() {
'three'
)
));
$expected = '/tests/index/pages[param1][0]:one/pages[param1][1]:two/pages[0]:three';
$expected = '/tests/index/pages%5Bparam1%5D%5B0%5D:one/pages%5Bparam1%5D%5B1%5D:two/pages%5B0%5D:three';
$this->assertEquals($expected, $result);

$result = Router::url(array('controller' => 'tests',
Expand All @@ -508,7 +508,7 @@ public function testArrayNamedParameters() {
'three'
)
));
$expected = '/tests/index/pages[param1][one]:1/pages[param1][two]:2/pages[0]:three';
$expected = '/tests/index/pages%5Bparam1%5D%5Bone%5D:1/pages%5Bparam1%5D%5Btwo%5D:2/pages%5B0%5D:three';
$this->assertEquals($expected, $result);

$result = Router::url(array('controller' => 'tests',
Expand All @@ -520,14 +520,14 @@ public function testArrayNamedParameters() {
'cool'
)
));
$expected = '/tests/index/super[nested][array]:awesome/super[nested][something]:else/super[0]:cool';
$expected = '/tests/index/super%5Bnested%5D%5Barray%5D:awesome/super%5Bnested%5D%5Bsomething%5D:else/super%5B0%5D:cool';
$this->assertEquals($expected, $result);

$result = Router::url(array('controller' => 'tests', 'namedParam' => array(
'keyed' => 'is an array',
'test'
)));
$expected = '/tests/index/namedParam[keyed]:is%20an%20array/namedParam[0]:test';
$expected = '/tests/index/namedParam%5Bkeyed%5D:is%20an%20array/namedParam%5B0%5D:test';
$this->assertEquals($expected, $result);
}

Expand Down

0 comments on commit fa6defe

Please sign in to comment.