Permalink
Browse files

Fix notice error when reading empty values.

When reading empty values a notice error would be triggered.
Slicing the first char off and comparing that solves this.

Fixes #2537
  • Loading branch information...
1 parent 6f91417 commit 7e17da0ae8a81cfde96bef4e7d4be553c487e821 @markstory markstory committed Feb 11, 2012
@@ -483,7 +483,8 @@ protected function _implode(array $array) {
* @return array Map of key and values
*/
protected function _explode($string) {
- if ($string[0] === '{' || $string[0] === '[') {
+ $first = substr($string, 0, 1);
+ if ($first !== false && $first === '{' || $first === '[') {
$ret = json_decode($string, true);
return ($ret != null) ? $ret : $string;
}
@@ -471,6 +471,21 @@ public function testReadLegacyCookieValue() {
$this->assertEquals($expected, $result);
}
+/**
+ * Test reading empty values.
+ */
+ public function testReadEmpty() {
+ $_COOKIE['CakeTestCookie'] = array(
+ 'JSON' => '{"name":"value"}',
+ 'Empty' => '',
+ 'String' => '{"somewhat:"broken"}'
+ );
+ $this->assertEqual(array('name' => 'value'), $this->Cookie->read('JSON'));
+ $this->assertEqual('value', $this->Cookie->read('JSON.name'));
+ $this->assertEqual('', $this->Cookie->read('Empty'));
+ $this->assertEqual('{"somewhat:"broken"}', $this->Cookie->read('String'));
+ }
+
/**
* test that no error is issued for non array data.
*
@@ -483,6 +498,7 @@ public function testNoErrorOnNonArrayData() {
$this->assertNull($this->Cookie->read('value'));
}
+
/**
* test that deleting a top level keys kills the child elements too.
*

0 comments on commit 7e17da0

Please sign in to comment.