Navigation Menu

Skip to content

Commit

Permalink
Fix a bug introduced when generating partial compatibility between 1.3
Browse files Browse the repository at this point in the history
and 2.0 Cookies, where an empty valued key caused a PHP notice. Also,
harden tests. Completes the fix for #2131.
  • Loading branch information
bar committed Jan 20, 2012
1 parent 27392bf commit 48d3fc7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cake/libs/controller/components/cookie.php
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/behaviors/translate.php
Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions cake/tests/cases/libs/controller/components/cookie.test.php
Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit 48d3fc7

Please sign in to comment.