From 8df535dbf9eabfec1b636b6d49913dd40bcaa428 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 6 Jan 2014 09:15:29 +0100 Subject: [PATCH] [BrowserKit] Throw exception on invalid cookie expiration timestamp --- src/Symfony/Component/BrowserKit/Cookie.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/BrowserKit/Cookie.php b/src/Symfony/Component/BrowserKit/Cookie.php index bce5613cf7a6..02194a14bfaf 100644 --- a/src/Symfony/Component/BrowserKit/Cookie.php +++ b/src/Symfony/Component/BrowserKit/Cookie.php @@ -81,6 +81,8 @@ public function __construct($name, $value, $expires = null, $path = null, $domai * * @return string The HTTP representation of the Cookie * + * @throws \UnexpectedValueException + * * @api */ public function __toString() @@ -88,7 +90,13 @@ 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) {