Skip to content
This repository was archived by the owner on Apr 8, 2019. It is now read-only.

Commit 42d2522

Browse files
committed
Parse the selector after unopened closing brackets properly
1 parent d8fd8dc commit 42d2522

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ private function parseListItem(CSSList $oList, $bIsRoot = false) {
129129
return $oAtRule;
130130
} else if ($this->comes('}')) {
131131
$this->consume('}');
132-
if ($bIsRoot && !$this->oParserSettings->bLenientParsing) {
133-
throw new SourceException("Unopened {", $this->iLineNo);
132+
if ($bIsRoot) {
133+
if ($this->oParserSettings->bLenientParsing) {
134+
while ($this->comes('}')) $this->consume('}');
135+
return $this->parseSelector();
136+
} else {
137+
throw new SourceException("Unopened {", $this->iLineNo);
138+
}
134139
} else {
135140
return null;
136141
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ function testCharsetFailure2() {
432432
$this->parsedStructureForFile('-charset-in-block', Settings::create()->withLenientParsing(false));
433433
}
434434

435+
/**
436+
* @expectedException Sabberworm\CSS\Parsing\SourceException
437+
*/
438+
function testUnopenedClosingBracketFailure() {
439+
$this->parsedStructureForFile('unopened-close-brackets', Settings::create()->withLenientParsing(false));
440+
}
441+
435442
function parsedStructureForFile($sFileName, $oSettings = null) {
436443
$sFile = dirname(__FILE__) . '/../../files' . DIRECTORY_SEPARATOR . "$sFileName.css";
437444
$oParser = new Parser(file_get_contents($sFile), $oSettings);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
}}}.blue{
2+
background: #00F;
3+
}

0 commit comments

Comments
 (0)