Skip to content

Commit dc57a12

Browse files
committed
Fixing remarks
1 parent 2b730e9 commit dc57a12

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/ChunkedDecoder.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function close()
7272
public function handleEnd()
7373
{
7474
if (!$this->closed) {
75-
$this->handleError(new \Exception('Unexpected `end` event'));
75+
$this->handleError(new \Exception('Unexpected end event'));
7676
}
7777
}
7878

@@ -90,17 +90,17 @@ public function handleData($data)
9090

9191
while ($this->buffer !== '') {
9292
if (!$this->headerCompleted) {
93-
$positionClrf = strpos($this->buffer, static::CRLF);
93+
$positionCrlf = strpos($this->buffer, static::CRLF);
9494

95-
if ($positionClrf === false) {
95+
if ($positionCrlf === false) {
9696
// Header shouldn't be bigger than 1024 bytes
9797
if (isset($this->buffer[static::MAX_CHUNK_HEADER_SIZE])) {
98-
$this->handleError(new \Exception('Chunk header size inclusive extension bigger than 1024 bytes'));
98+
$this->handleError(new \Exception('Chunk header size inclusive extension bigger than' . static::MAX_CHUNK_HEADER_SIZE. ' bytes'));
9999
}
100100
return;
101101
}
102102

103-
$header = strtolower((string)substr($this->buffer, 0, $positionClrf));
103+
$header = strtolower((string)substr($this->buffer, 0, $positionCrlf));
104104
$hexValue = $header;
105105

106106
if (strpos($header, ';') !== false) {
@@ -114,7 +114,7 @@ public function handleData($data)
114114
return;
115115
}
116116

117-
$this->buffer = (string)substr($this->buffer, $positionClrf + 2);
117+
$this->buffer = (string)substr($this->buffer, $positionCrlf + 2);
118118
$this->headerCompleted = true;
119119
if ($this->buffer === '') {
120120
return;
@@ -129,7 +129,9 @@ public function handleData($data)
129129
$this->buffer = (string)substr($this->buffer, strlen($chunk));
130130
}
131131

132-
if (strpos($this->buffer, static::CRLF) === 0) {
132+
$positionCrlf = strpos($this->buffer, static::CRLF);
133+
134+
if ($positionCrlf === 0) {
133135
if ($this->chunkSize === 0) {
134136
$this->emit('end');
135137
$this->close();
@@ -139,11 +141,15 @@ public function handleData($data)
139141
$this->headerCompleted = false;
140142
$this->transferredSize = 0;
141143
$this->buffer = (string)substr($this->buffer, 2);
142-
} else if ($this->chunkSize === $this->transferredSize && strlen($this->buffer) > 2) {
144+
}
145+
146+
if ($positionCrlf !== 0 && $this->chunkSize === $this->transferredSize && strlen($this->buffer) > 2) {
143147
// the first 2 characters are not CLRF, send error event
144148
$this->handleError(new \Exception('Chunk does not end with a CLRF'));
145149
return;
146-
} else if (strlen($this->buffer) < 2) {
150+
}
151+
152+
if ($positionCrlf !== 0 && strlen($this->buffer) < 2) {
147153
// No CLRF found, wait for additional data which could be a CLRF
148154
return;
149155
}

0 commit comments

Comments
 (0)