Permalink
Browse files

Merge pull request #435 from bar/cookie-2.0-compatibility

Cookie 2.0 compatibility
  • Loading branch information...
2 parents 27392bf + 48d3fc7 commit 359beccb1b4c1da93ab131bd4a6c44ef1f70ff5a @markstory markstory committed Jan 21, 2012
@@ -464,11 +464,11 @@ function __implode($array) {
* Explode method to return array from string set in CookieComponent::__implode()
*
* @param string $string String in the form key1|value1,key2|value2
- * @return array Map of key and values
+ * @return mixed If array, map of key and values. If string, value.
* @access private
*/
function __explode($string) {
- if (($string[0] === '{' || $string[0] === '[') && function_exists('json_decode')) {
+ if (!empty($string[0]) && ($string[0] === '{' || $string[0] === '[') && function_exists('json_decode')) {
$ret = json_decode($string, true);
return ($ret != null) ? $ret : $string;
}
@@ -110,7 +110,7 @@ function beforeFind(&$model, $query) {
}
$db =& ConnectionManager::getDataSource($model->useDbConfig);
$RuntimeModel =& $this->translateModel($model);
-
+
if (!empty($RuntimeModel->tablePrefix)) {
$tablePrefix = $RuntimeModel->tablePrefix;
} else {
@@ -487,9 +487,16 @@ function testForwardsCompatibility() {
if ($this->skipIf(!function_exists('json_decode'), 'no json_decode, skipping.')) {
return;
}
- $_COOKIE['CakeTestCookie'] = array('Test' => '{"name":"value"}');
+ $_COOKIE['CakeTestCookie'] = array(
+ 'JSON' => '{"name":"value"}',
+ 'Empty' => '',
+ 'String' => '{"somewhat:"broken"}'
+ );
$this->Controller->Cookie->startup($this->Controller);
- $this->assertEqual('value', $this->Controller->Cookie->read('Test.name'));
+ $this->assertEqual(array('name' => 'value'), $this->Controller->Cookie->read('JSON'));
+ $this->assertEqual('value', $this->Controller->Cookie->read('JSON.name'));
+ $this->assertEqual('', $this->Controller->Cookie->read('Empty'));
+ $this->assertEqual('{"somewhat:"broken"}', $this->Controller->Cookie->read('String'));
}
/**

0 comments on commit 359becc

Please sign in to comment.