8000 [BrowserKit] Throw exception on invalid cookie expiration timestamp · symfony/symfony@8df535d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8df535d

Browse files
anlutrofabpot
authored andcommitted
[BrowserKit] Throw exception on invalid cookie expiration timestamp
1 parent 146e666 commit 8df535d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,22 @@ public function __construct($name, $value, $expires = null, $path = null, $domai
8181
*
8282
* @return string The HTTP representation of the Cookie
8383
*
84+
* @throws \UnexpectedValueException
85+
*
8486
* @api
8587
*/
8688
public function __toString()
8789
{
8890
$cookie = sprintf('%s=%s', $this->name, $this->rawValue);
8991

9092
if (null !== $this->expires) {
91-
$cookie .= '; expires='.substr(\DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'))->format(self::$dateFormats[0]), 0, -5);
93+
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
94+
95+
if ($dateTime === false) {
96+
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $this->expires);
97+
}
98+
99+
$cookie .= '; expires='.substr($dateTime->format(self::$dateFormats[0]), 0, -5);
92100
}
93101

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

0 commit comments

Comments
 (0)
0