Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/107'
Browse files Browse the repository at this point in the history
Close #107
  • Loading branch information
weierophinney committed Jan 25, 2017
2 parents 29402ee + 9b7a30f commit a00cc26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions src/Header/Expires.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace Zend\Http\Header;

use DateTime;
use DateTimeZone;

/**
* Expires Header
*
Expand All @@ -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);
}
}
14 changes: 14 additions & 0 deletions test/Header/ExpiresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit a00cc26

Please sign in to comment.