Skip to content

Commit 6e845af

Browse files
committed
[TASK] Guard against infinite loop in parseList
This can't be tested because there are currently no cases that would fail the test without the change. It is there as a preventative double-lock measure to make sure any future code changes do not introduce an infinite loop. It's a slight unoptimization, as it adds what should be a redundant runtime check, but at miniscule performance cost versus the value of preventing a waste of CPU power and memory in the case that something goes wrong.
1 parent c7fb009 commit 6e845af

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/CSSList/CSSList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ public static function parseList(ParserState $parserState, CSSList $list): void
7272
$listItem = null;
7373
if ($usesLenientParsing) {
7474
try {
75+
$positionBeforeParse = $parserState->currentColumn();
7576
$listItem = self::parseListItem($parserState, $list);
7677
} catch (UnexpectedTokenException $e) {
7778
$listItem = false;
79+
// If the failed parsing did not consume anything ...
80+
if ($parserState->currentColumn() === $positionBeforeParse) {
81+
// ... the unexpected token needs to be skipped, otherwise there'll be an infinite loop.
82+
$parserState->consume(1);
83+
}
7884
}
7985
} else {
8086
$listItem = self::parseListItem($parserState, $list);

0 commit comments

Comments
 (0)