Skip to content

Commit 4f8da97

Browse files
committed
Update closing bracket parsing in a way which allows us to better match the browsers' parsing behavior
1 parent 15f1fdb commit 4f8da97

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList)
8383
}
8484
return $oAtRule;
8585
} else if ($oParserState->comes('}')) {
86-
$oParserState->consume('}');
8786
if ($bIsRoot) {
8887
if ($oParserState->getSettings()->bLenientParsing) {
89-
while ($oParserState->comes('}')) $oParserState->consume('}');
9088
return DeclarationBlock::parse($oParserState);
9189
} else {
9290
throw new SourceException("Unopened {", $oParserState->currentLine());
@@ -123,6 +121,9 @@ private static function parseAtRule(ParserState $oParserState) {
123121
$oResult->setVendorKeyFrame($sIdentifier);
124122
$oResult->setAnimationName(trim($oParserState->consumeUntil('{', false, true)));
125123
CSSList::parseList($oParserState, $oResult);
124+
if ($oParserState->comes('}')) {
125+
$oParserState->consume('}');
126+
}
126127
return $oResult;
127128
} else if ($sIdentifier === 'namespace') {
128129
$sPrefix = null;
@@ -162,6 +163,9 @@ private static function parseAtRule(ParserState $oParserState) {
162163
} else {
163164
$oAtRule = new AtRuleBlockList($sIdentifier, $sArgs, $iIdentifierLineNum);
164165
CSSList::parseList($oParserState, $oAtRule);
166+
if ($oParserState->comes('}')) {
167+
$oParserState->consume('}');
168+
}
165169
}
166170
return $oAtRule;
167171
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ function testCharsetFailure2() {
501501
* @expectedException \Sabberworm\CSS\Parsing\SourceException
502502
*/
503503
function testUnopenedClosingBracketFailure() {
504-
$this->parsedStructureForFile('unopened-close-brackets', Settings::create()->withLenientParsing(false));
504+
$this->parsedStructureForFile('-unopened-close-brackets', Settings::create()->withLenientParsing(false));
505505
}
506506

507507
/**

0 commit comments

Comments
 (0)