mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #2250 from luissquall/fix-cookie-explode
Parse cookie values "{}" & "[]" as array
This commit is contained in:
commit
5bd31621c1
2 changed files with 4 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue