Merge pull request #2250 from luissquall/fix-cookie-explode

Parse cookie values "{}" & "[]" as array
This commit is contained in:
Mark Story 2013-10-30 17:27:12 -07:00
commit 5bd31621c1
2 changed files with 4 additions and 2 deletions

View file

@ -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) {

View file

@ -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'));
}
/**