Skip to content

Commit

Permalink
Expanded fault-tolerance for unusual cookie dates
Browse files Browse the repository at this point in the history
  • Loading branch information
ecaron authored and fabpot committed Feb 22, 2013
1 parent 9f59ac9 commit 368f62f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Symfony/Component/BrowserKit/Cookie.php
Expand Up @@ -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',
);
Expand Down Expand Up @@ -203,6 +205,11 @@ private static function parseDate($dateValue)
}
}

// 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));
}

Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/BrowserKit/Tests/CookieTest.php
Expand Up @@ -56,9 +56,12 @@ public function getExpireCookieStrings()
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'),
);
}

Expand Down Expand Up @@ -86,7 +89,7 @@ public function testFromStringThrowsAnExceptionIfCookieIsNotValid()
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()
Expand Down

0 comments on commit 368f62f

Please sign in to comment.