From 9efad54e31998ecb64015774b1351260ad0f3110 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 6 Aug 2013 22:01:13 -0400 Subject: [PATCH] Fix missing expiry times on cookies. When writing multiple cookies in a single request with the default expiry time, cookies after the first should continue to have the default expiry time used. Fixes #3965 --- .../Controller/Component/CookieComponent.php | 2 +- .../Component/CookieComponentTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Component/CookieComponent.php b/lib/Cake/Controller/Component/CookieComponent.php index afe48b787..7ae79afeb 100644 --- a/lib/Cake/Controller/Component/CookieComponent.php +++ b/lib/Cake/Controller/Component/CookieComponent.php @@ -421,7 +421,7 @@ class CookieComponent extends Component { 'httpOnly' => $this->httpOnly )); - if (!is_null($this->_reset)) { + if (!empty($this->_reset)) { $this->_expires = $this->_reset; $this->_reset = null; } diff --git a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php index ad8ddb112..12371d83e 100644 --- a/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php @@ -203,6 +203,24 @@ class CookieComponentTest extends CakeTestCase { $this->assertEquals('value', $result); } +/** + * test that two write() calls use the expiry. + * + * @return void + */ + public function testWriteMultipleShareExpiry() { + $this->Cookie->write('key1', 'value1', false); + $this->Cookie->write('key2', 'value2', false); + + $name = $this->Cookie->name . '[key1]'; + $result = $this->Controller->response->cookie($name); + $this->assertWithinMargin(time() + 10, $result['expire'], 2, 'Expiry time is wrong'); + + $name = $this->Cookie->name . '[key2]'; + $result = $this->Controller->response->cookie($name); + $this->assertWithinMargin(time() + 10, $result['expire'], 2, 'Expiry time is wrong'); + } + /** * test write with distant future cookies *