Skip to content

Commit acc248c

Browse files
authored
Merge pull request MyIntervals#156 from raxbg/unmached_braces
Look for unmached brace count when parsing generic at-rules
2 parents 5697ef7 + c2b60df commit acc248c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/Sabberworm/CSS/CSSList/CSSList.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ private static function parseAtRule(ParserState $oParserState) {
142142
} else {
143143
//Unknown other at rule (font-face or such)
144144
$sArgs = trim($oParserState->consumeUntil('{', false, true));
145+
if (substr_count($sArgs, "(") != substr_count($sArgs, ")")) {
146+
if($oParserState->getSettings()->bLenientParsing) {
147+
return NULL;
148+
} else {
149+
throw new SourceException("Unmatched brace count in media query", $oParserState->currentLine());
150+
}
151+
}
145152
$bUseRuleSet = true;
146153
foreach(explode('/', AtRule::BLOCK_RULES) as $sBlockRuleName) {
147154
if(self::identifierIs($sIdentifier, $sBlockRuleName)) {

tests/Sabberworm/CSS/ParserTest.php

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

423+
function testUnmatchedBracesInFile() {
424+
$oDoc = $this->parsedStructureForFile('unmatched_braces', Settings::create()->withMultibyteSupport(true));
425+
$sExpected = 'button, input, checkbox, textarea {outline: 0;margin: 0;}';
426+
$this->assertSame($sExpected, $oDoc->render());
427+
}
428+
423429
/**
424430
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
425431
*/

tests/files/unmatched_braces.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
button,input,checkbox,textarea {
2+
outline: 0;
3+
margin: 0;
4+
}
5+
6+
@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) {
7+
#wrapper {
8+
max-width:640px;
9+
margin: 0 auto;
10+
}
11+
}
12+
13+
@media all and (orientation: landscape) {
14+
#wrapper {
15+
max-width:640px;
16+
margin: 0 auto;
17+
}
18+
}

0 commit comments

Comments
 (0)