Skip to content

Commit 0479a0e

Browse files
authored
Merge pull request #195 from NitroPack/fix/infinite_loop_linename
Prevent an infinite loop when parsing invalid grid line names
2 parents f225822 + 651e803 commit 0479a0e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lib/Sabberworm/CSS/Value/LineName.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public static function parse(ParserState $oParserState) {
1818
if($oParserState->getSettings()->bLenientParsing) {
1919
try {
2020
$aNames[] = $oParserState->parseIdentifier();
21-
} catch(UnexpectedTokenException $e) {}
21+
} catch(UnexpectedTokenException $e) {
22+
if (!$oParserState->comes(']')) {
23+
throw $e;
24+
}
25+
}
2226
} else {
2327
$aNames[] = $oParserState->parseIdentifier();
2428
}
@@ -28,8 +32,6 @@ public static function parse(ParserState $oParserState) {
2832
return new LineName($aNames, $oParserState->currentLine());
2933
}
3034

31-
32-
3335
public function __toString() {
3436
return $this->render(new \Sabberworm\CSS\OutputFormat());
3537
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@ function testEmptyGridLineNameLenientInFile() {
436436
$this->assertSame($sExpected, $oDoc->render());
437437
}
438438

439+
function testInvalidGridLineNameInFile() {
440+
$oDoc = $this->parsedStructureForFile('invalid-grid-linename', Settings::create()->withMultibyteSupport(true));
441+
$sExpected = "div {}";
442+
$this->assertSame($sExpected, $oDoc->render());
443+
}
444+
439445
function testUnmatchedBracesInFile() {
440446
$oDoc = $this->parsedStructureForFile('unmatched_braces', Settings::create()->withMultibyteSupport(true));
441447
$sExpected = 'button, input, checkbox, textarea {outline: 0;margin: 0;}';

tests/files/invalid-grid-linename.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
div { grid-template-columns: [ linename 100px; }

0 commit comments

Comments
 (0)