Skip to content

Commit

Permalink
Fix unclosed block comment tokenize
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jun 1, 2024
1 parent 25df6af commit 9b4d087
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,10 @@ private function createNextToken(string $string, Token|null $previous = null): T
$last = strpos($string, "\n");
$type = Token::TOKEN_TYPE_COMMENT;
} else { // Comment until closing comment tag
$pos = strpos($string, '*/', 2);
assert($pos !== false);
$last = $pos + 2;
$pos = strpos($string, '*/', 2);
$last = $pos !== false
? $pos + 2
: false;
$type = Token::TOKEN_TYPE_BLOCK_COMMENT;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/TokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public static function tokenizeData(): Generator
],
'\'foo...',
];

yield 'unclosed block comment' => [
[
new Token(Token::TOKEN_TYPE_BLOCK_COMMENT, '/* foo...'),
],
'/* foo...',
];
}

/** @return Generator<mixed[]> */
Expand Down

0 comments on commit 9b4d087

Please sign in to comment.