Skip to content

Commit 82ab538

Browse files
committed
Be friendly with unclosed comments in lenient mode
1 parent 6b5eec6 commit 82ab538

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,18 @@ private function consumeWhiteSpace() {
524524
while (preg_match('/\\s/isSu', $this->peek()) === 1) {
525525
$this->consume(1);
526526
}
527-
} while ($this->consumeComment());
527+
if($this->oParserSettings->bLenientParsing) {
528+
try {
529+
$bHasComment = $this->consumeComment();
530+
} catch(UnexpectedTokenException $e) {
531+
// When we can’t find the end of a comment, we assume the document is finished.
532+
$this->iCurrentPosition = $this->iLength;
533+
return;
534+
}
535+
} else {
536+
$bHasComment = $this->consumeComment();
537+
}
538+
} while($bHasComment);
528539
}
529540

530541
private function consumeComment() {

0 commit comments

Comments
 (0)