mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-26 20:14:46 +01:00
Fix Lexer errorHandling when there is no tokens
I encounter an issue when no tokens exist. An error `Undefined offset -1` is triggered.
This commit is contained in:
parent
3da86df48f
commit
c28b8556f5
@ -185,15 +185,17 @@ class Lexer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for unterminated comment
|
if (count($this->tokens) > 0) {
|
||||||
$lastToken = $this->tokens[count($this->tokens) - 1];
|
// Check for unterminated comment
|
||||||
if ($this->isUnterminatedComment($lastToken)) {
|
$lastToken = $this->tokens[count($this->tokens) - 1];
|
||||||
$errorHandler->handleError(new Error('Unterminated comment', [
|
if ($this->isUnterminatedComment($lastToken)) {
|
||||||
'startLine' => $line - substr_count($lastToken[1], "\n"),
|
$errorHandler->handleError(new Error('Unterminated comment', [
|
||||||
'endLine' => $line,
|
'startLine' => $line - substr_count($lastToken[1], "\n"),
|
||||||
'startFilePos' => $filePos - \strlen($lastToken[1]),
|
'endLine' => $line,
|
||||||
'endFilePos' => $filePos,
|
'startFilePos' => $filePos - \strlen($lastToken[1]),
|
||||||
]));
|
'endFilePos' => $filePos,
|
||||||
|
]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,13 @@ class LexerTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(), array()
|
array(), array()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
// tests no tokens
|
||||||
|
array(
|
||||||
|
'',
|
||||||
|
array(),
|
||||||
|
array()
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user