Skip to content

Commit 264c003

Browse files
author
Maciej Mroziński
committed
Trim leading zeros from chunk size
1 parent ec3f739 commit 264c003

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/ChunkedStreamDecoder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ protected function iterateBuffer()
111111
if (strpos($lengthChunk, ';') !== false) {
112112
list($lengthChunk) = explode(';', $lengthChunk, 2);
113113
}
114+
$lengthChunk = ltrim($lengthChunk, "0");
114115
if (dechex(hexdec($lengthChunk)) !== $lengthChunk) {
115116
$this->emit('error', [
116117
new Exception('Unable to validate "' . $lengthChunk . '" as chunk length header'),

tests/DecodeChunkedStreamTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ public function provideChunkedEncoding()
4343
["6\r\nWi\r\n", "ki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"],
4444
"Wi\r\nkipedia in\r\n\r\nchunks."
4545
],
46+
'varnish-type-response-1' => [
47+
["0017\r\nWikipedia in\r\n\r\nchunks.\r\n0\r\n\r\n"]
48+
],
49+
'varnish-type-response-2' => [
50+
["004\r\nWiki\r\n005\r\npedia\r\n00e\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"]
51+
],
52+
'varnish-type-response-extra-line' => [
53+
["006\r\nWi\r\nki\r\n005\r\npedia\r\n00e\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"],
54+
"Wi\r\nkipedia in\r\n\r\nchunks."
55+
]
4656
];
4757
}
4858

0 commit comments

Comments
 (0)