diff --git a/lib/Sabberworm/CSS/CSSList/CSSList.php b/lib/Sabberworm/CSS/CSSList/CSSList.php index 3736d8f3..d883df82 100644 --- a/lib/Sabberworm/CSS/CSSList/CSSList.php +++ b/lib/Sabberworm/CSS/CSSList/CSSList.php @@ -142,6 +142,13 @@ private static function parseAtRule(ParserState $oParserState) { } else { //Unknown other at rule (font-face or such) $sArgs = trim($oParserState->consumeUntil('{', false, true)); + if (substr_count($sArgs, "(") != substr_count($sArgs, ")")) { + if($oParserState->getSettings()->bLenientParsing) { + return NULL; + } else { + throw new SourceException("Unmatched brace count in media query", $oParserState->currentLine()); + } + } $bUseRuleSet = true; foreach(explode('/', AtRule::BLOCK_RULES) as $sBlockRuleName) { if(self::identifierIs($sIdentifier, $sBlockRuleName)) { diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php index 0922b11e..0bee410c 100644 --- a/tests/Sabberworm/CSS/ParserTest.php +++ b/tests/Sabberworm/CSS/ParserTest.php @@ -420,6 +420,12 @@ function testEmptyGridLineNameLenientInFile() { $this->assertSame($sExpected, $oDoc->render()); } + function testUnmatchedBracesInFile() { + $oDoc = $this->parsedStructureForFile('unmatched_braces', Settings::create()->withMultibyteSupport(true)); + $sExpected = 'button, input, checkbox, textarea {outline: 0;margin: 0;}'; + $this->assertSame($sExpected, $oDoc->render()); + } + /** * @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException */ diff --git a/tests/files/unmatched_braces.css b/tests/files/unmatched_braces.css new file mode 100644 index 00000000..b7172762 --- /dev/null +++ b/tests/files/unmatched_braces.css @@ -0,0 +1,18 @@ +button,input,checkbox,textarea { + outline: 0; + margin: 0; +} + +@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio:3/@media all and (orientation:portrait) { + #wrapper { + max-width:640px; + margin: 0 auto; + } +} + +@media all and (orientation: landscape) { + #wrapper { + max-width:640px; + margin: 0 auto; + } +}