Skip to content

Commit

Permalink
[BrowserKit] Throw exception on invalid cookie expiration timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
anlutro authored and fabpot committed Jan 6, 2014
1 parent 146e666 commit 8df535d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Symfony/Component/BrowserKit/Cookie.php
Expand Up @@ -81,14 +81,22 @@ public function __construct($name, $value, $expires = null, $path = null, $domai
*
* @return string The HTTP representation of the Cookie
*
* @throws \UnexpectedValueException
*
* @api
*/
public function __toString()
{
$cookie = sprintf('%s=%s', $this->name, $this->rawValue);

if (null !== $this->expires) {
$cookie .= '; expires='.substr(\DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'))->format(self::$dateFormats[0]), 0, -5);
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));

if ($dateTime === false) {
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $this->expires);
}

$cookie .= '; expires='.substr($dateTime->format(self::$dateFormats[0]), 0, -5);
}

if ('' !== $this->domain) {
Expand Down

0 comments on commit 8df535d

Please sign in to comment.