Skip to content
This repository
Browse code

url encode nested named parameters in unmatched routes

reference: #2988
and 3103323
  • Loading branch information...
commit fa6defea3764de1fe98f5178737cd1829757758f 1 parent 52f2060
Andy Dawson authored
4  lib/Cake/Routing/Router.php
@@ -945,9 +945,9 @@ protected static function _handleNoRoute($url) {
945 945
 		if (!empty($named)) {
946 946
 			foreach ($named as $name => $value) {
947 947
 				if (is_array($value)) {
948  
-					$flattend = Hash::flatten($value, '][');
  948
+					$flattend = Hash::flatten($value, '%5D%5B');
949 949
 					foreach ($flattend as $namedKey => $namedValue) {
950  
-						$output .= '/' . $name . "[$namedKey]" . self::$_namedConfig['separator'] . rawurlencode($namedValue);
  950
+						$output .= '/' . $name . "%5B{$namedKey}%5D" . self::$_namedConfig['separator'] . rawurlencode($namedValue);
951 951
 					}
952 952
 				} else {
953 953
 					$output .= '/' . $name . self::$_namedConfig['separator'] . rawurlencode($value);
10  lib/Cake/Test/Case/Routing/RouterTest.php
@@ -484,7 +484,7 @@ public function testArrayNamedParameters() {
484 484
 		$result = Router::url(array('controller' => 'tests', 'pages' => array(
485 485
 			1, 2, 3
486 486
 		)));
487  
-		$expected = '/tests/index/pages[0]:1/pages[1]:2/pages[2]:3';
  487
+		$expected = '/tests/index/pages%5B0%5D:1/pages%5B1%5D:2/pages%5B2%5D:3';
488 488
 		$this->assertEquals($expected, $result);
489 489
 
490 490
 		$result = Router::url(array('controller' => 'tests',
@@ -496,7 +496,7 @@ public function testArrayNamedParameters() {
496 496
 				'three'
497 497
 			)
498 498
 		));
499  
-		$expected = '/tests/index/pages[param1][0]:one/pages[param1][1]:two/pages[0]:three';
  499
+		$expected = '/tests/index/pages%5Bparam1%5D%5B0%5D:one/pages%5Bparam1%5D%5B1%5D:two/pages%5B0%5D:three';
500 500
 		$this->assertEquals($expected, $result);
501 501
 
502 502
 		$result = Router::url(array('controller' => 'tests',
@@ -508,7 +508,7 @@ public function testArrayNamedParameters() {
508 508
 				'three'
509 509
 			)
510 510
 		));
511  
-		$expected = '/tests/index/pages[param1][one]:1/pages[param1][two]:2/pages[0]:three';
  511
+		$expected = '/tests/index/pages%5Bparam1%5D%5Bone%5D:1/pages%5Bparam1%5D%5Btwo%5D:2/pages%5B0%5D:three';
512 512
 		$this->assertEquals($expected, $result);
513 513
 
514 514
 		$result = Router::url(array('controller' => 'tests',
@@ -520,14 +520,14 @@ public function testArrayNamedParameters() {
520 520
 				'cool'
521 521
 			)
522 522
 		));
523  
-		$expected = '/tests/index/super[nested][array]:awesome/super[nested][something]:else/super[0]:cool';
  523
+		$expected = '/tests/index/super%5Bnested%5D%5Barray%5D:awesome/super%5Bnested%5D%5Bsomething%5D:else/super%5B0%5D:cool';
524 524
 		$this->assertEquals($expected, $result);
525 525
 
526 526
 		$result = Router::url(array('controller' => 'tests', 'namedParam' => array(
527 527
 			'keyed' => 'is an array',
528 528
 			'test'
529 529
 		)));
530  
-		$expected = '/tests/index/namedParam[keyed]:is%20an%20array/namedParam[0]:test';
  530
+		$expected = '/tests/index/namedParam%5Bkeyed%5D:is%20an%20array/namedParam%5B0%5D:test';
531 531
 		$this->assertEquals($expected, $result);
532 532
 	}
533 533
 

0 notes on commit fa6defe

Please sign in to comment.
Something went wrong with that request. Please try again.