Skip to content

Commit

Permalink
Move tests to valid ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Mroziński committed Feb 28, 2017
1 parent 7e904b7 commit 3c9ab0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/ChunkedStreamDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ protected function iterateBuffer()
if (strpos($lengthChunk, ';') !== false) {
list($lengthChunk) = explode(';', $lengthChunk, 2);
}
$lengthChunk = ltrim($lengthChunk, "0");
if ($lengthChunk !== '') {
$lengthChunk = ltrim($lengthChunk, "0");
if ($lengthChunk === '') {
$lengthChunk = "0";
}
}
if (dechex(hexdec($lengthChunk)) !== $lengthChunk) {
$this->emit('error', [
new Exception('Unable to validate "' . $lengthChunk . '" as chunk length header'),
Expand Down
18 changes: 9 additions & 9 deletions tests/DecodeChunkedStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public function provideChunkedEncoding()
],
'varnish-type-response-random' => [
[str_repeat("0", rand(0, 10)), "4\r\nWiki\r\n", str_repeat("0", rand(0, 10)), "5\r\npedia\r\n", str_repeat("0", rand(0, 10)), "e\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"]
],
'end-chunk-zero-check-1' => [
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n00\r\n\r\n"]
],
'end-chunk-zero-check-2' => [
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n000\r\n\r\n"]
],
'end-chunk-zero-check-3' => [
["00004\r\nWiki\r\n005\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0000\r\n\r\n"]
]
];
}
Expand Down Expand Up @@ -100,15 +109,6 @@ public function provideInvalidChunkedEncoding()
],
'header-chunk-to-long' => [
str_split(str_repeat('a', 2015) . "\r\nWi\r\nki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n")
],
'end-chunk-zero-check-1' => [
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n00\r\n\r\n"]
],
'end-chunk-zero-check-2' => [
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n000\r\n\r\n"]
],
'end-chunk-zero-check-3' => [
["00004\r\nWiki\r\n005\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0000\r\n\r\n"]
]
];
}
Expand Down

0 comments on commit 3c9ab0a

Please sign in to comment.