Skip to content

Commit

Permalink
bug #19827 [BrowserKit] Fix cookie expiration on 32 bit systems (jame…
Browse files Browse the repository at this point in the history
…shalsall)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #19827).

Discussion
----------

[BrowserKit] Fix cookie expiration on 32 bit systems

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #15739
| License       | MIT

On 32-bit systems the cookie expiration value was not being calculated
correctly as it was being fetched as an integer. When the timestamp exceeded
the PHP_INT_MAX size it would return an invalid value, breaking the cookie
construction.

The BrowserKit cookie has now been updated to get the timestamp as a string
which works around this platform limitation (similar to how it works in the Cookie
from HttpFoundation).

Commits
-------

68698f2 [BrowserKit] Fix cookie expiration on 32 bit systems
  • Loading branch information
fabpot committed Sep 2, 2016
2 parents 2511f2a + 68698f2 commit 053d67b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Component/BrowserKit/Cookie.php
Expand Up @@ -76,7 +76,7 @@ public function __construct($name, $value, $expires = null, $path = null, $domai
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires));
}

$this->expires = $timestampAsDateTime->getTimestamp();
$this->expires = $timestampAsDateTime->format('U');
}
}

Expand Down Expand Up @@ -205,13 +205,13 @@ private static function parseDate($dateValue)

foreach (self::$dateFormats as $dateFormat) {
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
return $date->getTimestamp();
return $date->format('U');
}
}

// attempt a fallback for unusual formatting
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
return $date->getTimestamp();
return $date->format('U');
}

throw new \InvalidArgumentException(sprintf('Could not parse date "%s".', $dateValue));
Expand Down Expand Up @@ -304,6 +304,6 @@ public function isHttpOnly()
*/
public function isExpired()
{
return null !== $this->expires && 0 !== $this->expires && $this->expires < time();
return null !== $this->expires && 0 != $this->expires && $this->expires < time();
}
}

0 comments on commit 053d67b

Please sign in to comment.