Skip to content

Commit

Permalink
bug #4049 Fix a warning (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Fix a warning

Closes #4048

Commits
-------

ccc20cb Fix a warning
  • Loading branch information
fabpot committed Apr 24, 2024
2 parents 861c76c + ccc20cb commit 24b73b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lexer.php
Expand Up @@ -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('=>');
}
Expand Down
23 changes: 23 additions & 0 deletions tests/LexerTest.php
Expand Up @@ -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 ['{{ ..'];
}
}

0 comments on commit 24b73b8

Please sign in to comment.