diff --git a/src/Lexer.php b/src/Lexer.php index 4d7cffdd1..e15e896f5 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -321,7 +321,7 @@ private function lexExpression(): void $this->moveCursor('...'); } // arrow function - elseif ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) { + elseif ('=' === $this->code[$this->cursor] && ($this->cursor + 1 < $this->end) && '>' === $this->code[$this->cursor + 1]) { $this->pushToken(Token::ARROW_TYPE, '=>'); $this->moveCursor('=>'); } diff --git a/tests/LexerTest.php b/tests/LexerTest.php index ad62c22ac..2aad47ac9 100644 --- a/tests/LexerTest.php +++ b/tests/LexerTest.php @@ -378,4 +378,27 @@ public function testOverridingSyntax() // can be executed without throwing any exceptions $this->addToAssertionCount(1); } + + /** + * @dataProvider getTemplateForErrorsAtTheEndOfTheStream + */ + public function testErrorsAtTheEndOfTheStream(string $template) + { + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); + set_error_handler(function () { + $this->fail('Lexer should not emit warnings.'); + }); + try { + $lexer->tokenize(new Source($template, 'index')); + $this->addToAssertionCount(1); + } finally { + restore_error_handler(); + } + } + + public function getTemplateForErrorsAtTheEndOfTheStream() + { + yield ['{{ =']; + yield ['{{ ..']; + } }