diff --git a/src/Decoder.php b/src/Decoder.php index 6bd07ef..3aa8eb7 100644 --- a/src/Decoder.php +++ b/src/Decoder.php @@ -99,6 +99,12 @@ public function pipe(WritableStreamInterface $dest, array $options = array()) /** @internal */ public function handleData($data) { + + if (!\is_string($data)) { + $this->handleError(new \UnexpectedValueException('Expected stream to emit string, but got ' . \gettype($data))); + return; + } + $this->buffer .= $data; // keep parsing while a newline has been found diff --git a/tests/DecoderTest.php b/tests/DecoderTest.php index 4e25b45..0743e6b 100644 --- a/tests/DecoderTest.php +++ b/tests/DecoderTest.php @@ -67,6 +67,14 @@ public function testEmitDataBigIntOptionWillForwardAsString() $this->input->emit('data', array("999888777666555444333222111000\n")); } + public function testEmitDataWithInvalidTypeWillForwardErrorWithUnexpectedValueException() + { + $this->decoder->on('data', $this->expectCallableNever()); + $this->decoder->on('error', $this->expectCallableOnceWith($this->isInstanceOf('UnexpectedValueException'))); + + $this->input->emit('data', array(false)); + } + public function testEmitDataErrorWillForwardError() { $this->decoder->on('data', $this->expectCallableNever());