diff --git a/Cake/Controller/Component/CookieComponent.php b/Cake/Controller/Component/CookieComponent.php index 54458583ba6..694de688c3f 100644 --- a/Cake/Controller/Component/CookieComponent.php +++ b/Cake/Controller/Component/CookieComponent.php @@ -488,7 +488,7 @@ protected function _encrypt($value) { if (is_array($value)) { $value = $this->_implode($value); } - if (!$this->_encrypted || !$value) { + if (!$this->_encrypted) { return $value; } $prefix = "Q2FrZQ==."; diff --git a/Cake/Test/TestCase/Controller/Component/CookieComponentTest.php b/Cake/Test/TestCase/Controller/Component/CookieComponentTest.php index b9e3e3fb8f6..9319aaf8842 100644 --- a/Cake/Test/TestCase/Controller/Component/CookieComponentTest.php +++ b/Cake/Test/TestCase/Controller/Component/CookieComponentTest.php @@ -175,11 +175,11 @@ public function testWriteSimple() { } /** - * test write() Encrypted data with null & empty string & boolean value + * test write() encrypted data with falsey value * * @return void */ - public function testWriteWithNullEmptyString() { + public function testWriteWithFalseyValue() { $this->Cookie->type('aes'); $this->Cookie->key = 'qSI232qs*&sXOw!adre@34SAv!@*(XSL#$%)asGb$@11~_+!@#HKis~#^'; @@ -201,7 +201,11 @@ public function testWriteWithNullEmptyString() { $this->Cookie->write('Testing', '0'); $result = $this->Cookie->read('Testing'); - $this->assertEquals('0', $result); + $this->assertSame('0', $result); + + $this->Cookie->write('Testing', 0); + $result = $this->Cookie->read('Testing'); + $this->assertSame(0, $result); } /** diff --git a/Cake/Test/TestCase/Utility/SecurityTest.php b/Cake/Test/TestCase/Utility/SecurityTest.php index c62f3cd8511..f07debdd873 100644 --- a/Cake/Test/TestCase/Utility/SecurityTest.php +++ b/Cake/Test/TestCase/Utility/SecurityTest.php @@ -294,16 +294,27 @@ public function testEncryptInvalidKey() { } /** - * Test that empty data cause errors + * Test encrypting falsey data * - * @expectedException Cake\Error\Exception - * @expectedExceptionMessage The data to encrypt cannot be empty. * @return void */ - public function testEncryptInvalidData() { - $txt = ''; + public function testEncryptDecryptFalseyData() { $key = 'This is a key that is long enough to be ok.'; - Security::encrypt($txt, $key); + + $result = Security::encrypt('', $key); + $this->assertSame('', Security::decrypt($result, $key)); + + $result = Security::encrypt(false, $key); + $this->assertSame('', Security::decrypt($result, $key)); + + $result = Security::encrypt(null, $key); + $this->assertSame('', Security::decrypt($result, $key)); + + $result = Security::encrypt(0, $key); + $this->assertSame('0', Security::decrypt($result, $key)); + + $result = Security::encrypt('0', $key); + $this->assertSame('0', Security::decrypt($result, $key)); } /** diff --git a/Cake/Utility/Security.php b/Cake/Utility/Security.php index fa985a30ae6..c3e16b31fda 100644 --- a/Cake/Utility/Security.php +++ b/Cake/Utility/Security.php @@ -238,9 +238,7 @@ protected static function _crypt($password, $salt = false) { */ public static function encrypt($plain, $key, $hmacSalt = null) { self::_checkKey($key, 'encrypt()'); - if (strlen($plain) === 0) { - throw new Error\Exception(__d('cake_dev', 'The data to encrypt cannot be empty.')); - } + if ($hmacSalt === null) { $hmacSalt = Configure::read('Security.salt'); }