Skip to content

Commit 9b4d087

Browse files
committed
Fix unclosed block comment tokenize
1 parent 25df6af commit 9b4d087

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Tokenizer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,10 @@ private function createNextToken(string $string, Token|null $previous = null): T
825825
$last = strpos($string, "\n");
826826
$type = Token::TOKEN_TYPE_COMMENT;
827827
} else { // Comment until closing comment tag
828-
$pos = strpos($string, '*/', 2);
829-
assert($pos !== false);
830-
$last = $pos + 2;
828+
$pos = strpos($string, '*/', 2);
829+
$last = $pos !== false
830+
? $pos + 2
831+
: false;
831832
$type = Token::TOKEN_TYPE_BLOCK_COMMENT;
832833
}
833834

tests/TokenizerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ public static function tokenizeData(): Generator
120120
],
121121
'\'foo...',
122122
];
123+
124+
yield 'unclosed block comment' => [
125+
[
126+
new Token(Token::TOKEN_TYPE_BLOCK_COMMENT, '/* foo...'),
127+
],
128+
'/* foo...',
129+
];
123130
}
124131

125132
/** @return Generator<mixed[]> */

0 commit comments

Comments
 (0)