Expanded fault-tolerance for unusual cookie dates
This commit is contained in:
parent
9f59ac907b
commit
368f62f19c
@ -30,6 +30,8 @@ class Cookie
|
||||
'D, d M Y H:i:s T',
|
||||
'D, d-M-y H:i:s T',
|
||||
'D, d-M-Y H:i:s T',
|
||||
'D, d-m-y H:i:s T',
|
||||
'D, d-m-Y H:i:s T',
|
||||
'D M j G:i:s Y',
|
||||
'D M d H:i:s Y T',
|
||||
);
|
||||
@ -203,6 +205,11 @@ class Cookie
|
||||
}
|
||||
}
|
||||
|
||||
// attempt a fallback for unusual formatting
|
||||
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
|
||||
return $date->getTimestamp();
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('Could not parse date "%s".', $dateValue));
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,12 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
array('foo=bar; expires=Fri, 31-Jul-2020 08:49:37 GMT'),
|
||||
array('foo=bar; expires=Fri, 31 Jul 2020 08:49:37 GMT'),
|
||||
array('foo=bar; expires=Fri, 31-07-2020 08:49:37 GMT'),
|
||||
array('foo=bar; expires=Fri, 31-07-20 08:49:37 GMT'),
|
||||
array('foo=bar; expires=Friday, 31-Jul-20 08:49:37 GMT'),
|
||||
array('foo=bar; expires=Fri Jul 31 08:49:37 2020'),
|
||||
array('foo=bar; expires=\'Fri Jul 31 08:49:37 2020\''),
|
||||
array('foo=bar; expires=Friday July 31st 2020, 08:49:37 GMT'),
|
||||
);
|
||||
}
|
||||
|
||||
@ -86,7 +89,7 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
public function testFromStringThrowsAnExceptionIfCookieDateIsNotValid()
|
||||
{
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
Cookie::FromString('foo=bar; expires=foo');
|
||||
Cookie::FromString('foo=bar; expires=Flursday July 31st 2020, 08:49:37 GMT');
|
||||
}
|
||||
|
||||
public function testFromStringThrowsAnExceptionIfUrlIsNotValid()
|
||||
|
Reference in New Issue
Block a user