Skip to content

Commit

Permalink
[HttpFoundation] more sophisticated checks for valid expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalkaoz committed Mar 5, 2011
1 parent 727326b commit 87e1359
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Symfony/Component/HttpFoundation/Cookie.php
Expand Up @@ -40,11 +40,16 @@ public function __construct($name, $value = null, $expire = 0, $path = null, $do
if (empty($name)) {
throw new \InvalidArgumentException('The cookie name cannot be empty');
}

//check if the expiration is valid
if(!$expire instanceof \DateTime && !is_numeric($expire) && (strtotime($expire) === false || strtotime($expire) === -1)){
throw new \InvalidArgumentException('The cookie expiration is not valid');
}

$this->name = $name;
$this->value = $value;
$this->domain = $domain;
$this->expire = (integer) $expire;
$this->expire = $expire;
$this->path = $path;
$this->secure = (Boolean) $secure;
$this->httponly = (Boolean) $httponly;
Expand Down
8 changes: 8 additions & 0 deletions tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php
Expand Up @@ -68,6 +68,14 @@ public function testInstantiationThrowsExceptionIfCookieValueContainsInvalidChar
{
new Cookie('MyCookie', $value);
}

/**
* @expectedException InvalidArgumentException
*/
public function testInvalidExpiration()
{
$cookie = new Cookie('MyCookie', 'foo','bar');
}

/**
* @covers Symfony\Component\HttpFoundation\Cookie::getValue
Expand Down

0 comments on commit 87e1359

Please sign in to comment.