diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a3b3d6c3..10e717b2f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#107](https://github.com/zendframework/zend-http/pull/107) fixes the + `Expires` header to allow values of `0` or `'0'`; these now resolve + to the start of the unix epoch (1970-01-01). ## 2.5.5 - 2016-08-08 diff --git a/src/Header/Expires.php b/src/Header/Expires.php index ff2de5c82d..dec223cad0 100644 --- a/src/Header/Expires.php +++ b/src/Header/Expires.php @@ -9,6 +9,9 @@ namespace Zend\Http\Header; +use DateTime; +use DateTimeZone; + /** * Expires Header * @@ -25,4 +28,13 @@ public function getFieldName() { return 'Expires'; } + + + public function setDate($date) + { + if ($date === '0' || $date === 0) { + $date = date(DATE_W3C, 0); // Thu, 01 Jan 1970 00:00:00 GMT + } + return parent::setDate($date); + } } diff --git a/test/Header/ExpiresTest.php b/test/Header/ExpiresTest.php index 359ee8f3fb..c46b7dca46 100644 --- a/test/Header/ExpiresTest.php +++ b/test/Header/ExpiresTest.php @@ -54,4 +54,18 @@ public function testPreventsCRLFAttackViaFromString() { $header = Expires::fromString("Expires: Sun, 06 Nov 1994 08:49:37 GMT\r\n\r\nevilContent"); } + + public function testExpiresSetToZero() + { + $expires = Expires::fromString("Expires: 0"); + $this->assertEquals('Expires: Thu, 01 Jan 1970 00:00:00 GMT', $expires->toString()); + + $expires = new Expires(); + $expires->setDate('0'); + $this->assertEquals('Expires: Thu, 01 Jan 1970 00:00:00 GMT', $expires->toString()); + + $expires = new Expires(); + $expires->setDate(0); + $this->assertEquals('Expires: Thu, 01 Jan 1970 00:00:00 GMT', $expires->toString()); + } }