Skip to content

Commit

Permalink
Fix handling of empty input
Browse files Browse the repository at this point in the history
Fixes #967.
  • Loading branch information
nikic committed Dec 20, 2023
1 parent f82a636 commit f7d484a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/PhpParser/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function postprocessTokens(array &$tokens, ErrorHandler $errorHandler)
$numTokens = \count($tokens);
if ($numTokens === 0) {
// Empty input edge case: Just add the sentinel token.
$tokens[] = [new Token(0, "\0", 1, 0)];
$tokens[] = new Token(0, "\0", 1, 0);
return;
}

Expand Down
6 changes: 6 additions & 0 deletions test/code/parser/emptyFile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Empty file
-----

-----
array(
)

0 comments on commit f7d484a

Please sign in to comment.