Skip to content

Commit 3c9ab0a

Browse files
author
Maciej Mroziński
committed
Move tests to valid ones
1 parent 7e904b7 commit 3c9ab0a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/ChunkedStreamDecoder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ protected function iterateBuffer()
111111
if (strpos($lengthChunk, ';') !== false) {
112112
list($lengthChunk) = explode(';', $lengthChunk, 2);
113113
}
114-
$lengthChunk = ltrim($lengthChunk, "0");
114+
if ($lengthChunk !== '') {
115+
$lengthChunk = ltrim($lengthChunk, "0");
116+
if ($lengthChunk === '') {
117+
$lengthChunk = "0";
118+
}
119+
}
115120
if (dechex(hexdec($lengthChunk)) !== $lengthChunk) {
116121
$this->emit('error', [
117122
new Exception('Unable to validate "' . $lengthChunk . '" as chunk length header'),

tests/DecodeChunkedStreamTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ public function provideChunkedEncoding()
6464
],
6565
'varnish-type-response-random' => [
6666
[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"]
67+
],
68+
'end-chunk-zero-check-1' => [
69+
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n00\r\n\r\n"]
70+
],
71+
'end-chunk-zero-check-2' => [
72+
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n000\r\n\r\n"]
73+
],
74+
'end-chunk-zero-check-3' => [
75+
["00004\r\nWiki\r\n005\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0000\r\n\r\n"]
6776
]
6877
];
6978
}
@@ -100,15 +109,6 @@ public function provideInvalidChunkedEncoding()
100109
],
101110
'header-chunk-to-long' => [
102111
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")
103-
],
104-
'end-chunk-zero-check-1' => [
105-
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n00\r\n\r\n"]
106-
],
107-
'end-chunk-zero-check-2' => [
108-
["4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n000\r\n\r\n"]
109-
],
110-
'end-chunk-zero-check-3' => [
111-
["00004\r\nWiki\r\n005\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0000\r\n\r\n"]
112112
]
113113
];
114114
}

0 commit comments

Comments
 (0)