Skip to content

Commit 2e809a7

Browse files
committed
Simplified Decoder::getSafeBoundary()
1 parent 5fa9740 commit 2e809a7

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/Decoder.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,14 @@ protected function digitException(): DecodingException
266266
*/
267267
protected function getSafeBoundary(): int
268268
{
269-
$boundary = $this->len - 1;
270-
do
269+
if (str_ends_with($this->bencoded, 'e'))
271270
{
272-
$c = substr($this->bencoded, $boundary, 1);
271+
return $this->len - 1;
273272
}
274-
while (str_contains('0123456789', $c) && --$boundary >= 0);
275273

276-
return match ($c)
277-
{
278-
'-' => $boundary - 2,
279-
'i' => $boundary - 1,
280-
default => $boundary
281-
};
274+
preg_match('(i?-?[0-9]*+$)D', $this->bencoded, $m);
275+
276+
return $this->len - 1 - strlen($m[0] ?? '');
282277
}
283278

284279
protected function readDigits(string $terminator): string

0 commit comments

Comments
 (0)