From db63ba2d8f95e67b6b212860f0310ed65ab4db6a Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 30 Oct 2013 15:26:50 -0600 Subject: [PATCH 1/2] Parse cookie values "{}" & "[]" as array --- lib/Cake/Controller/Component/CookieComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index a062f565a..419d46945 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -534,7 +534,7 @@ class CookieComponent extends Component { $first = substr($string, 0, 1); if ($first === '{' || $first === '[') { $ret = json_decode($string, true); - return ($ret) ? $ret : $string; + return ($ret !== null) ? $ret : $string; } $array = array(); foreach (explode(',', $string) as $pair) { From e33653a8d7f5910782577ae6bc7518e172938a4c Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 30 Oct 2013 16:06:27 -0600 Subject: [PATCH 2/2] Add test case --- .../Test/Case/Controller/Component/CookieComponentTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php index 9b0488f57..0fd3558af 100644 --- a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php @@ -601,12 +601,14 @@ class CookieComponentTest extends CakeTestCase { $_COOKIE['CakeTestCookie'] = array( 'JSON' => '{"name":"value"}', 'Empty' => '', - 'String' => '{"somewhat:"broken"}' + 'String' => '{"somewhat:"broken"}', + 'Array' => '{}' ); $this->assertEquals(array('name' => 'value'), $this->Cookie->read('JSON')); $this->assertEquals('value', $this->Cookie->read('JSON.name')); $this->assertEquals('', $this->Cookie->read('Empty')); $this->assertEquals('{"somewhat:"broken"}', $this->Cookie->read('String')); + $this->assertEquals(array(), $this->Cookie->read('Array')); } /**