Skip to content

Commit

Permalink
Merge pull request #2039 from neerolyte/fix-cookie-isexpired-check-5-3
Browse files Browse the repository at this point in the history
Fix bug parsing 0 epoch expiry times
  • Loading branch information
sagikazarmark committed Jun 20, 2018
2 parents f9acb47 + 1ae1d86 commit af094f5
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 @@ -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
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 af094f5

Please sign in to comment.