Skip to content

Commit 184b610

Browse files
committed
Handle arithmetic operators in Value
1 parent f734920 commit 184b610

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/Value/CSSFunction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function parseName(ParserState $oParserState, $bIgnoreCase = false
5959
*/
6060
public static function parseArgs(ParserState $oParserState)
6161
{
62-
return Value::parseValue($oParserState, ['=', ' ', ',', '/', '*', '+', '-']);
62+
return Value::parseValue($oParserState, ['=', ' ', ',']);
6363
}
6464

6565
/**

src/Value/Value.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,16 @@ public static function parsePrimitiveValue(ParserState $oParserState)
156156
} elseif ($oParserState->comes("U+")) {
157157
$oValue = self::parseUnicodeRangeValue($oParserState);
158158
} else {
159-
$oValue = self::parseIdentifierOrFunction($oParserState);
159+
$sNextChar = $oParserState->peek(1);
160+
try {
161+
$oValue = self::parseIdentifierOrFunction($oParserState);
162+
} catch (UnexpectedTokenException $e) {
163+
if (in_array($sNextChar, ['+', '-', '*', '/'])) {
164+
$oValue = $oParserState->consume(1);
165+
} else {
166+
throw $e;
167+
}
168+
}
160169
}
161170
$oParserState->consumeWhiteSpace();
162171
return $oValue;

tests/ParserTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,10 +1231,10 @@ public function lonelyImport()
12311231
public function functionArithmeticInFile()
12321232
{
12331233
$oDoc = self::parsedStructureForFile('function-arithmetic', Settings::create()->withMultibyteSupport(true));
1234-
$sExpected = 'div {height: max(300,vh+10);}
1235-
div {height: max(300,vh-10);}
1236-
div {height: max(300,vh*10);}
1237-
div {height: max(300,vh/10);}';
1234+
$sExpected = 'div {height: max(300,vh + 10);}
1235+
div {height: max(300,vh - 10);}
1236+
div {height: max(300,vh * 10);}
1237+
div {height: max(300,vh / 10);}';
12381238
self::assertSame($sExpected, $oDoc->render());
12391239
}
12401240

0 commit comments

Comments
 (0)