diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index 84ece7f8..f18cd772 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -72,9 +72,15 @@ public static function parseList(ParserState $parserState, CSSList $list): void $listItem = null; if ($usesLenientParsing) { try { + $positionBeforeParse = $parserState->currentColumn(); $listItem = self::parseListItem($parserState, $list); } catch (UnexpectedTokenException $e) { $listItem = false; + // If the failed parsing did not consume anything that was to come ... + if ($parserState->currentColumn() === $positionBeforeParse && !$parserState->isEnd()) { + // ... the unexpected token needs to be skipped, otherwise there'll be an infinite loop. + $parserState->consume(1); + } } } else { $listItem = self::parseListItem($parserState, $list); diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index df825377..44f96a94 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -192,6 +192,10 @@ public function parseCharacter(bool $isForIdentifier): ?string * * @throws UnexpectedEOFException * @throws UnexpectedTokenException + * + * @phpstan-impure + * This method may change the state of the object by advancing the internal position; + * it does not simply 'get' a value. */ public function consumeWhiteSpace(): array {