diff --git a/src/Tokenizer.php b/src/Tokenizer.php index 82ace8c..2ac597d 100644 --- a/src/Tokenizer.php +++ b/src/Tokenizer.php @@ -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; } diff --git a/tests/TokenizerTest.php b/tests/TokenizerTest.php index 71c53a1..f8a767e 100644 --- a/tests/TokenizerTest.php +++ b/tests/TokenizerTest.php @@ -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 */