Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Fixed handling of empty output in abstract stream filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Apr 8, 2014
1 parent d422ad2 commit 1c63f4b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AbstractNativeStreamFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function filter($input, $output, &$consumed, $isEnd)
$this->buffer = substr($this->buffer, $thisConsumed);
}

if ('' !== $outputBuffer) {
if (null !== $outputBuffer) {
$bucket->data = $outputBuffer;
stream_bucket_append($output, $bucket);
$hasOutput = true;
Expand Down
4 changes: 2 additions & 2 deletions src/CompoundTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public function transform($data, &$context, $isEnd = false)
$currentContext = $context[$transform];
$currentContext->buffer .= $data;

list($data, $bytesConsumed, $error) = $transform->transform(
list($data, $consumed, $error) = $transform->transform(
$currentContext->buffer,
$currentContext->context,
$isEnd
);

$currentContext->buffer = substr(
$currentContext->buffer,
$bytesConsumed
$consumed
);

if (false === $currentContext->buffer) {
Expand Down
6 changes: 5 additions & 1 deletion src/TransformStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ private function transformBuffer()
$this->buffer = substr($this->buffer, $consumed);
}

if (null !== $output) {
if ($this->isEnding || null !== $output) {
if (null === $output) {
$output = '';
}

$this->emit('data', array($output, $this));
}

Expand Down
2 changes: 1 addition & 1 deletion test/src/Base64DecodeTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function transform($data, &$context, $isEnd = false)
{
$consume = $this->blocksSize(strlen($data), 4, $isEnd);
if (!$consume) {
return array('', 0, null);
return array(null, 0, null);
}

$consumedData = substr($data, 0, $consume);
Expand Down
2 changes: 1 addition & 1 deletion test/src/Md5Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function transform($data, &$context, $isEnd = false)
if ($isEnd) {
$output = hash_final($context);
} else {
$output = '';
$output = null;
}

return array($output, strlen($data), null);
Expand Down

0 comments on commit 1c63f4b

Please sign in to comment.