Skip to content

Commit 47f146d

Browse files
ecaronfabpot
authored andcommitted
Expanded fault-tolerance for unusual cookie dates
1 parent 90d3b68 commit 47f146d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Cookie.php

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Cookie
3030
'D, d M Y H:i:s T',
3131
'D, d-M-y H:i:s T',
3232
'D, d-M-Y H:i:s T',
33+
'D, d-m-y H:i:s T',
34+
'D, d-m-Y H:i:s T',
3335
'D M j G:i:s Y',
3436
'D M d H:i:s Y T',
3537
);
@@ -203,6 +205,11 @@ private static function parseDate($dateValue)
203205
}
204206
}
205207

208+
// attempt a fallback for unusual formatting
209+
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
210+
return $date->getTimestamp();
211+
}
212+
206213
throw new \InvalidArgumentException(sprintf('Could not parse date "%s".', $dateValue));
207214
}
208215

Tests/CookieTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ public function getExpireCookieStrings()
5656
return array(
5757
array('foo=bar; expires=Fri, 31-Jul-2020 08:49:37 GMT'),
5858
array('foo=bar; expires=Fri, 31 Jul 2020 08:49:37 GMT'),
59+
array('foo=bar; expires=Fri, 31-07-2020 08:49:37 GMT'),
60+
array('foo=bar; expires=Fri, 31-07-20 08:49:37 GMT'),
5961
array('foo=bar; expires=Friday, 31-Jul-20 08:49:37 GMT'),
6062
array('foo=bar; expires=Fri Jul 31 08:49:37 2020'),
6163
array('foo=bar; expires=\'Fri Jul 31 08:49:37 2020\''),
64+
array('foo=bar; expires=Friday July 31st 2020, 08:49:37 GMT'),
6265
);
6366
}
6467

@@ -86,7 +89,7 @@ public function testFromStringThrowsAnExceptionIfCookieIsNotValid()
8689
public function testFromStringThrowsAnExceptionIfCookieDateIsNotValid()
8790
{
8891
$this->setExpectedException('InvalidArgumentException');
89-
Cookie::FromString('foo=bar; expires=foo');
92+
Cookie::FromString('foo=bar; expires=Flursday July 31st 2020, 08:49:37 GMT');
9093
}
9194

9295
public function testFromStringThrowsAnExceptionIfUrlIsNotValid()

0 commit comments

Comments
 (0)