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

Commit dfd2e32

Browse files
committed
Merge branch 'hotfix/87'
Close #87 Fixes #26
2 parents e9fb717 + 0edda91 commit dfd2e32

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ All notable changes to this project will be documented in this file, in reverse
2424

2525
### Fixed
2626

27-
- Nothing.
27+
- [#87](https://github.com/zendframework/zend-http/pull/87) fixes the
28+
`ContentLength` constructor to test for a non null value (vs a falsy value)
29+
before validating the value; this ensures 0 values may be specified for the
30+
length.
2831

2932
## 2.5.4 - 2016-02-04
3033

src/Header/ContentLength.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function fromString($headerLine)
4040

4141
public function __construct($value = null)
4242
{
43-
if ($value) {
43+
if (null !== $value) {
4444
HeaderValue::assertValid($value);
4545
$this->value = $value;
4646
}

test/Header/ContentLengthTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@ public function testPreventsCRLFAttackViaConstructor()
6565
$this->setExpectedException('Zend\Http\Header\Exception\InvalidArgumentException');
6666
$header = new ContentLength("Content-Length: xxx\r\n\r\nevilContent");
6767
}
68+
69+
public function testZeroValue()
70+
{
71+
$contentLengthHeader = new ContentLength(0);
72+
$this->assertEquals(0, $contentLengthHeader->getFieldValue());
73+
$this->assertEquals('Content-Length: 0', $contentLengthHeader->toString());
74+
}
6875
}

0 commit comments

Comments
 (0)