Skip to content

Commit d16b92a

Browse files
committed
Fix an issue in parsing calc functions with whitespace after the operands/operators
1 parent a90142f commit d16b92a

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

lib/Sabberworm/CSS/Value/CalcFunction.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ public static function parse(ParserState $oParserState) {
2121
if ($oParserState->comes('(')) {
2222
$iNestingLevel++;
2323
$oCalcList->addListComponent($oParserState->consume(1));
24+
$oParserState->consumeWhiteSpace();
2425
continue;
2526
} else if ($oParserState->comes(')')) {
2627
$iNestingLevel--;
2728
$oCalcList->addListComponent($oParserState->consume(1));
29+
$oParserState->consumeWhiteSpace();
2830
continue;
2931
}
3032
if ($iLastComponentType != CalcFunction::T_OPERAND) {
@@ -53,6 +55,7 @@ public static function parse(ParserState $oParserState) {
5355
);
5456
}
5557
}
58+
$oParserState->consumeWhiteSpace();
5659
}
5760
$oList->addListComponent($oCalcList);
5861
$oParserState->consume(')');

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ function testCalcInFile() {
404404
$oDoc = $this->parsedStructureForFile('calc', Settings::create()->withMultibyteSupport(true));
405405
$sExpected = 'div {width: calc(100% / 4);}
406406
div {margin-top: calc(-120% - 4px);}
407-
div {height: -webkit-calc(9 / 16 * 100%) !important;width: -moz-calc(( 50px - 50% ) * 2);}';
407+
div {height: -webkit-calc(9 / 16 * 100%) !important;width: -moz-calc(( 50px - 50% ) * 2);}
408+
div {width: calc(50% - ( ( 4% ) * .5 ));}';
408409
$this->assertSame($sExpected, $oDoc->render());
409410
}
410411

tests/files/calc.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ div {
44
height: -webkit-calc(9/16 * 100%)!important;
55
width: -moz-calc((50px - 50%)*2);
66
}
7+
div { width: calc(50% - ( ( 4% ) * 0.5 ) ); }

0 commit comments

Comments
 (0)