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

Commit 798ee00

Browse files
committed
Merge branch 'hotfix/257'
Close #257 Fixes #255
2 parents f1b5954 + 73c2645 commit 798ee00

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ All notable changes to this project will be documented in this file, in reverse
2929
response instance do not override those set by PHP when a session is created
3030
and/or regenerated.
3131

32+
- [#257](https://github.com/zendframework/zend-diactoros/pull/257) provides a
33+
fix for the `PhpInputStream::read()` method to ensure string content that
34+
evaluates as empty (including `0`) is still cached.
35+
3236
## 1.4.0 - 2017-04-06
3337

3438
### Added

src/PhpInputStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function isWritable()
5959
public function read($length)
6060
{
6161
$content = parent::read($length);
62-
if ($content && ! $this->reachedEof) {
62+
if (! $this->reachedEof) {
6363
$this->cache .= $content;
6464
}
6565

test/PhpInputStreamTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ public function testGetContentsReturnsRemainingContentsOfStream()
6464
$this->assertEquals(substr($contents, 128), $remainder);
6565
}
6666

67+
public function testGetContentsReturnCacheWhenReachedEof()
68+
{
69+
$this->stream->getContents();
70+
$this->assertStreamContents($this->stream->getContents());
71+
72+
$stream = new PhpInputStream('data://,0');
73+
$stream->read(1);
74+
$stream->read(1);
75+
$this->assertSame('0', $stream->getContents(), 'Don\'t evaluate 0 as empty');
76+
}
77+
6778
public function testCastingToStringReturnsFullContentsRegardlesOfPriorReads()
6879
{
6980
$start = $this->stream->read(128);

0 commit comments

Comments
 (0)