Skip to content

Commit 34c0f1b

Browse files
committed
bug symfony#9949 [BrowserKit] Throw exception on invalid cookie expiration timestamp (anlutro)
This PR was squashed before being merged into the 2.3 branch (closes symfony#9949). Discussion ---------- [BrowserKit] Throw exception on invalid cookie expiration timestamp Currently, if an invalid timestamp is provided, a fatal error with no stack trace will occur, making it difficult to trace the problem. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 8df535d [BrowserKit] Throw exception on invalid cookie expiration timestamp
2 parents 146e666 + 8df535d commit 34c0f1b

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)