Skip to content

Commit 81143bd

Browse files
committed
Detect invalid calc definitions like 'calc ('
1 parent 823bf14 commit 81143bd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/Sabberworm/CSS/Value/CalcFunction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ class CalcFunction extends CSSFunction {
1212
public static function parse(ParserState $oParserState) {
1313
$aOperators = array('+', '-', '*', '/');
1414
$aTerminators = array('(', ';', "\n", "\r");
15-
$sFunction = trim($oParserState->consumeUntil($aTerminators, false, true));
15+
$sFunction = $oParserState->consumeUntil($aTerminators, false, true);
1616
if ($oParserState->peek(1, -1) != '(') {
1717
// Found ; or end of line before an opening bracket
1818
throw new UnexpectedTokenException('(', $oParserState->peek(1, -1), 'literal', $oParserState->currentLine());
19+
} else if (!in_array($sFunction, array('calc', '-moz-calc', '-webkit-calc'))) {
20+
// Found invalid calc definition. Example calc (...
21+
throw new UnexpectedTokenException('calc', $sFunction, 'literal', $oParserState->currentLine());
1922
}
2023
$oCalcList = new CalcRuleValueList($oParserState->currentLine());
2124
$oList = new RuleValueList(',', $oParserState->currentLine());

0 commit comments

Comments
 (0)