Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/5677'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Mar 4, 2014
2 parents 7bb00c2 + 860f756 commit fba45eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Header/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,24 @@ public function setExpires($expires)
return $this;
}

$tsExpires = $expires;
if (is_string($expires)) {
$expires = strtotime($expires);
$tsExpires = strtotime($expires);

// if $tsExpires is invalid and PHP is compiled as 32bit. Check if it fail reason is the 2038 bug
if (!is_int($tsExpires) && PHP_INT_SIZE === 4) {
$dateTime = new \DateTime($expires);
if ( $dateTime->format('Y') > 2038) {
$tsExpires = PHP_INT_MAX;
}
}
}

if (!is_int($expires) || $expires < 0) {
if (!is_int($tsExpires) || $tsExpires < 0) {
throw new Exception\InvalidArgumentException('Invalid expires time specified');
}

$this->expires = $expires;
$this->expires = $tsExpires;
return $this;
}

Expand Down
13 changes: 13 additions & 0 deletions test/Header/SetCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ public function testSetCookieSetExpiresWithUnixEpochString()
$this->assertSame($target, $setCookieHeader->getFieldValue());
}

/**
* Check that setCookie does not fail when an expiry date which is bigger then 2038 is supplied (effect only 32bit systems)
*/
public function testSetCookieSetExpiresWithStringDateBiggerThen2038()
{
if ( PHP_INT_SIZE !== 4 ) {
$this->markTestSkipped('Testing set cookie expiry which is over 2038 is only relevant on 32bit systems');
return;
}
$setCookieHeader = new SetCookie('myname', 'myvalue', 'Thu, 01-Jan-2040 00:00:00 GMT');
$this->assertSame(2147483647, $setCookieHeader->getExpires(true));
}

public function testIsValidForRequestSubdomainMatch()
{
$setCookieHeader = new SetCookie(
Expand Down

0 comments on commit fba45eb

Please # to comment.