diff --git a/src/TwigComponent/src/Twig/TwigPreLexer.php b/src/TwigComponent/src/Twig/TwigPreLexer.php index 6043f2699c7..caf83cd27cc 100644 --- a/src/TwigComponent/src/Twig/TwigPreLexer.php +++ b/src/TwigComponent/src/Twig/TwigPreLexer.php @@ -366,8 +366,10 @@ private function consumeAttributes(string $componentName): string */ private function consume(string $string): bool { - if (str_starts_with(substr($this->input, $this->position), $string)) { - $this->position += \strlen($string); + $length = \strlen($string); + + if ($this->position + $length <= $this->length && 0 === substr_compare($this->input, $string, $this->position, $length)) { + $this->position += $length; return true; }