Fix handling of unterminated comment with trailing newline

Fixes #688.
This commit is contained in:
Nikita Popov 2020-07-22 18:35:11 +02:00
parent 17f478107a
commit 739b4b4c60
3 changed files with 7 additions and 1 deletions

View File

@ -7,6 +7,10 @@ Version 4.7.0-dev
* [PHP 8.0] Added support for match expressions. These are represented using a new `Expr\Match_`
containing `MatchArm`s.
### Fixed
* Fixed missing error for unterminated comment with trailing newline (#688).
Version 4.6.0 (2020-07-02)
--------------------------

View File

@ -152,7 +152,8 @@ class Lexer
$this->handleInvalidCharacterRange($filePos, $filePos + 1, $line, $errorHandler);
}
if ($token[0] === \T_COMMENT && preg_match('/(\r\n|\n|\r)$/D', $token[1], $matches)) {
if ($token[0] === \T_COMMENT && substr($token[1], 0, 2) !== '/*'
&& preg_match('/(\r\n|\n|\r)$/D', $token[1], $matches)) {
$trailingNewline = $matches[0];
$token[1] = substr($token[1], 0, -strlen($trailingNewline));
$this->tokens[$i] = $token;

View File

@ -35,6 +35,7 @@ class LexerTest extends \PHPUnit\Framework\TestCase
public function provideTestError() {
return [
["<?php /*", ["Unterminated comment from 1:7 to 1:9"]],
["<?php /*\n", ["Unterminated comment from 1:7 to 2:1"]],
["<?php \1", ["Unexpected character \"\1\" (ASCII 1) from 1:7 to 1:7"]],
["<?php \0", ["Unexpected null byte from 1:7 to 1:7"]],
// Error with potentially emulated token