diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 55df787b2..72886003b 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -378,6 +378,9 @@ class CakeRoute { * @return array An array with persistent parameters applied. */ public function persistParams($url, $params) { + if (empty($this->options['persist']) || !is_array($this->options['persist'])) { + return $url; + } foreach ($this->options['persist'] as $persistKey) { if (array_key_exists($persistKey, $params) && !isset($url[$persistKey])) { $url[$persistKey] = $params[$persistKey]; diff --git a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php index 93fa7c514..d0d3c1742 100644 --- a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php +++ b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php @@ -484,6 +484,40 @@ class CakeRouteTest extends CakeTestCase { $this->assertEquals('red', $result['color']); } +/** + * test persist with a non array value + * + * @return void + */ + public function testPersistParamsNonArray() { + $url = array('controller' => 'posts', 'action' => 'index'); + $params = array('lang' => 'en', 'color' => 'blue'); + + $route = new CakeRoute( + '/:lang/:color/blog/:action', + array('controller' => 'posts') + // No persist options + ); + $result = $route->persistParams($url, $params); + $this->assertEquals($url, $result); + + $route = new CakeRoute( + '/:lang/:color/blog/:action', + array('controller' => 'posts'), + array('persist' => false) + ); + $result = $route->persistParams($url, $params); + $this->assertEquals($url, $result); + + $route = new CakeRoute( + '/:lang/:color/blog/:action', + array('controller' => 'posts'), + array('persist' => 'derp') + ); + $result = $route->persistParams($url, $params); + $this->assertEquals($url, $result); + } + /** * test the parse method of CakeRoute. *