Skip to content

Commit 0c74522

Browse files
authored
Merge pull request MyIntervals#130 from raxbg/discard_unopened_close_brackets
Discard unopened close brackets
2 parents 0b14b3b + 42d2522 commit 0c74522

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ private function parseListItem(CSSList $oList, $bIsRoot = false) {
132132
} else if ($this->comes('}')) {
133133
$this->consume('}');
134134
if ($bIsRoot) {
135-
throw new SourceException("Unopened {", $this->iLineNo);
135+
if ($this->oParserSettings->bLenientParsing) {
136+
while ($this->comes('}')) $this->consume('}');
137+
return $this->parseSelector();
138+
} else {
139+
throw new SourceException("Unopened {", $this->iLineNo);
140+
}
136141
} else {
137142
return null;
138143
}

tests/Sabberworm/CSS/ParserTest.php

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

449+
/**
450+
* @expectedException Sabberworm\CSS\Parsing\SourceException
451+
*/
452+
function testUnopenedClosingBracketFailure() {
453+
$this->parsedStructureForFile('unopened-close-brackets', Settings::create()->withLenientParsing(false));
454+
}
455+
449456
function parsedStructureForFile($sFileName, $oSettings = null) {
450457
$sFile = dirname(__FILE__) . '/../../files' . DIRECTORY_SEPARATOR . "$sFileName.css";
451458
$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)