Commit cbcc7b6a by Qiang Xue

Fixes #2264: `CookieCollection::has()` will return false for expired or removed cookies

parent 84d4cd28
...@@ -20,6 +20,7 @@ Yii Framework 2 Change Log ...@@ -20,6 +20,7 @@ Yii Framework 2 Change Log
- Bug #3194: Date formatter works only for timestamps in the year range 1970 to 2038 (kartik-v) - Bug #3194: Date formatter works only for timestamps in the year range 1970 to 2038 (kartik-v)
- Bug #3204: `yii\di\Container` did not handle the `$config` parameter well in case when it does not have a default value (qiangxue) - Bug #3204: `yii\di\Container` did not handle the `$config` parameter well in case when it does not have a default value (qiangxue)
- Bug #3216: Fixed the bug that `yii.activeForm.destroy()` did not remove `submit` event handlers (qiangxue) - Bug #3216: Fixed the bug that `yii.activeForm.destroy()` did not remove `submit` event handlers (qiangxue)
- Enh #2264: `CookieCollection::has()` will return false for expired or removed cookies (qiangxue)
- Enh #2837: Error page now shows arguments in stack trace method calls (samdark) - Enh #2837: Error page now shows arguments in stack trace method calls (samdark)
- Enh #3008: Added `Html::errorSummary()` (qiangxue) - Enh #3008: Added `Html::errorSummary()` (qiangxue)
- Enh #3088: The debug and gii modules will manage their own URL rules now (hiltonjanfield, qiangxue) - Enh #3088: The debug and gii modules will manage their own URL rules now (hiltonjanfield, qiangxue)
......
...@@ -102,12 +102,15 @@ class CookieCollection extends Object implements \IteratorAggregate, \ArrayAcces ...@@ -102,12 +102,15 @@ class CookieCollection extends Object implements \IteratorAggregate, \ArrayAcces
/** /**
* Returns whether there is a cookie with the specified name. * Returns whether there is a cookie with the specified name.
* Note that if a cookie is marked for deletion from browser, this method will return false.
* @param string $name the cookie name * @param string $name the cookie name
* @return boolean whether the named cookie exists * @return boolean whether the named cookie exists
* @see remove()
*/ */
public function has($name) public function has($name)
{ {
return isset($this->_cookies[$name]); return isset($this->_cookies[$name]) && $this->_cookies[$name]->value !== ''
&& ($this->_cookies[$name]->expire === null || $this->_cookies[$name]->expire >= time());
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment