Skip to content

Commit

Permalink
Fix bug parsing 0 epoch expiry times
Browse files Browse the repository at this point in the history
As per #1952 expiry times
specified as "Thu, 01 Jan 1970 00:00:00 GMT" should be treated as
expired, but they weren't because 0 was implicitly casting to a bool in
SetCookie::isExpired().
  • Loading branch information
neerolyte committed Apr 3, 2018
1 parent f9acb47 commit 1ae1d86
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Cookie/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function matchesDomain($domain)
*/
public function isExpired()
{
return $this->getExpires() && time() > $this->getExpires();
return $this->getExpires() !== null && time() > $this->getExpires();
}

/**
Expand Down
41 changes: 41 additions & 0 deletions tests/Cookie/SetCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,45 @@ public function testParseCookie($cookie, $parsed)
}
}
}

/**
* Provides the data for testing isExpired
*
* @return array
*/
public function isExpiredProvider() {
return array(
array(
'FOO=bar; expires=Thu, 01 Jan 1970 00:00:00 GMT;',
true,
),
array(
'FOO=bar; expires=Thu, 01 Jan 1970 00:00:01 GMT;',
true,
),
array(
'FOO=bar; expires='.date(\DateTime::RFC1123, time()+10).';',
false,
),
array(
'FOO=bar; expires='.date(\DateTime::RFC1123, time()-10).';',
true,
),
array(
'FOO=bar;',
false,
),
);
}

/**
* @dataProvider isExpiredProvider
*/
public function testIsExpired($cookie, $expired)
{
$this->assertEquals(
$expired,
SetCookie::fromString($cookie)->isExpired()
);
}
}

0 comments on commit 1ae1d86

Please sign in to comment.