Skip to content

Commit

Permalink
Merge pull request #2014 from neerolyte/fix-cookie-isexpired-check
Browse files Browse the repository at this point in the history
Fix bug parsing 0 epoch expiry times
  • Loading branch information
sagikazarmark committed Mar 26, 2018
2 parents ba1bce3 + 2a7d3a4 commit 9e6a3fa
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
Expand Up @@ -358,7 +358,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
Expand Up @@ -396,4 +396,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 9e6a3fa

Please sign in to comment.