Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ All notable changes to this project will be documented in this file, in reverse
codes 226, 308, 444, 499, 510, 599 with their corresponding constants and
reason phrases.

### Changed

- [#120](https://github.com/zendframework/zend-http/pull/120) Changes handling
of Cookie Max-Age parameter to conform to specification
[rfc6265#section-5.2.2](https://tools.ietf.org/html/rfc6265#section-5.2.2).
Specifically, non-numeric values are ignored and negative numbers are changed
to 0.

### Deprecated

- Nothing.
Expand Down
10 changes: 5 additions & 5 deletions src/Header/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
$header->setVersion((int) $headerValue);
break;
case 'maxage':
$header->setMaxAge((int) $headerValue);
$header->setMaxAge($headerValue);
break;
default:
// Intentionally omitted
Expand Down Expand Up @@ -342,15 +342,15 @@ public function getVersion()
* Set Max-Age
*
* @param int $maxAge
* @throws Exception\InvalidArgumentException
* @return SetCookie
*/
public function setMaxAge($maxAge)
{
if ($maxAge !== null && (! is_int($maxAge) || ($maxAge < 0))) {
throw new Exception\InvalidArgumentException('Invalid Max-Age number specified');
if ($maxAge === null || ! is_numeric($maxAge)) {
return $this;
}
$this->maxAge = $maxAge;

$this->maxAge = max(0, (int) $maxAge);
return $this;
}

Expand Down
27 changes: 27 additions & 0 deletions test/Header/SetCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,33 @@ public static function validCookieWithInfoProvider()
],
'emptykey=; Domain=docs.foo.com',
],
[
'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=foo;',
[
'name' => 'myname',
'value' => '',
'domain' => 'docs.foo.com',
],
'emptykey=; Domain=docs.foo.com'
],
[
'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=-1480312904;',
[
'name' => 'myname',
'value' => '',
'domain' => 'docs.foo.com',
],
'emptykey=; Max-Age=0; Domain=docs.foo.com'
],
[
'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=100;',
[
'name' => 'myname',
'value' => '',
'domain' => 'docs.foo.com',
],
'emptykey=; Max-Age=100; Domain=docs.foo.com'
],
];
}
}