diff --git a/src/ChunkedStreamDecoder.php b/src/ChunkedStreamDecoder.php index 1402077..703eee3 100644 --- a/src/ChunkedStreamDecoder.php +++ b/src/ChunkedStreamDecoder.php @@ -103,7 +103,7 @@ protected function iterateBuffer() list($lengthChunk) = explode(';', $lengthChunk, 2); } if ($lengthChunk !== '') { - $lengthChunk = ltrim($lengthChunk, "0"); + $lengthChunk = ltrim(trim($lengthChunk), "0"); if ($lengthChunk === '') { // We've reached the end of the stream $this->reachedEnd = true; diff --git a/tests/DecodeChunkedStreamTest.php b/tests/DecodeChunkedStreamTest.php index 435dc00..62aa84f 100644 --- a/tests/DecodeChunkedStreamTest.php +++ b/tests/DecodeChunkedStreamTest.php @@ -76,6 +76,13 @@ public function provideChunkedEncoding() ], 'uppercase-chunk' => [ ["4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"], + ], + 'extra-space-in-length-chunk' => [ + [" 04 \r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"], + ], + 'only-whitespace-is-final-chunk' => [ + [" \r\n\r\n"], + "" ] ]; }