Skip to content

Commit

Permalink
fix CookieComponent - when write null or empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
zoghal committed Dec 14, 2013
1 parent e61ac62 commit 11f543f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/CookieComponent.php
Expand Up @@ -472,7 +472,7 @@ protected function _encrypt($value) {
if (is_array($value)) { if (is_array($value)) {
$value = $this->_implode($value); $value = $this->_implode($value);
} }
if (!$this->_encrypted) { if (!$this->_encrypted || !$value) {
return $value; return $value;
} }
$prefix = "Q2FrZQ==."; $prefix = "Q2FrZQ==.";
Expand Down
30 changes: 30 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php
Expand Up @@ -201,6 +201,36 @@ public function testWriteSimple() {
$this->assertEquals('value', $result); $this->assertEquals('value', $result);
} }


/**
* test write() Encrypted data with null & empty string & boolean value
*
* @return void
*/
public function testWriteWithNullEmptyString() {
$this->Cookie->type('aes');
$this->Cookie->key = 'qSI232qs*&sXOw!adre@34SAv!@*(XSL#$%)asGb$@11~_+!@#HKis~#^';

$this->Cookie->write('Testing');
$result = $this->Cookie->read('Testing');
$this->assertNull($result);

$this->Cookie->write('Testing', '');
$result = $this->Cookie->read('Testing');
$this->assertEquals('', $result);

$this->Cookie->write('Testing', false);
$result = $this->Cookie->read('Testing');
$this->assertFalse($result);

$this->Cookie->write('Testing', 1);
$result = $this->Cookie->read('Testing');
$this->assertEquals(1, $result);

$this->Cookie->write('Testing', '0');
$result = $this->Cookie->read('Testing');
$this->assertEquals('0', $result);
}

/** /**
* test that two write() calls use the expiry. * test that two write() calls use the expiry.
* *
Expand Down

0 comments on commit 11f543f

Please sign in to comment.