diff --git a/lib/Sabberworm/CSS/Value/Value.php b/lib/Sabberworm/CSS/Value/Value.php index fccc26bb..7e156cb4 100644 --- a/lib/Sabberworm/CSS/Value/Value.php +++ b/lib/Sabberworm/CSS/Value/Value.php @@ -68,7 +68,15 @@ public static function parseIdentifierOrFunction(ParserState $oParserState, $bIg if ($oParserState->comes('(')) { $oParserState->consume('('); $aArguments = Value::parseValue($oParserState, array('=', ' ', ',')); - $sResult = new CSSFunction($sResult, $aArguments, ',', $oParserState->currentLine()); + + if ($sResult == 'url') { + $sResult = new URL($aArguments, $oParserState->currentLine()); + } else if ($sResult == 'calc') { + $sResult = new CalcFunction($sResult, $aArguments, ',', $oParserState->currentLine()); + } else { + $sResult = new CSSFunction($sResult, $aArguments, ',', $oParserState->currentLine()); + } + $oParserState->consume(')'); } diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php index a6d95359..0c4deea5 100644 --- a/tests/Sabberworm/CSS/ParserTest.php +++ b/tests/Sabberworm/CSS/ParserTest.php @@ -746,4 +746,14 @@ function testMicrosoftFilterParsing() { $sExpected = ".test {filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\"#80000000\",endColorstr=\"#00000000\",GradientType=1);}"; $this->assertSame($sExpected, $oDoc->render()); } + + function testEscapedSpecialCaseTokens() { + $oDoc = $this->parsedStructureForFile('escaped-tokens'); + $contents = $oDoc->getContents(); + $rules = $contents[0]->getRules(); + $urlRule = $rules[0]; + $calcRule = $rules[1]; + $this->assertEquals(true, is_a($urlRule->getValue(), '\Sabberworm\CSS\Value\URL')); + $this->assertEquals(true, is_a($calcRule->getValue(), '\Sabberworm\CSS\Value\CalcFunction')); + } } diff --git a/tests/files/escaped-tokens.css b/tests/files/escaped-tokens.css new file mode 100644 index 00000000..0b894334 --- /dev/null +++ b/tests/files/escaped-tokens.css @@ -0,0 +1,7 @@ +/** + * Special case function-like tokens, with an escape backslash followed by a non-newline and non-hex digit character, should be parsed as the appropriate \Sabberworm\CSS\Value\ type + */ +body { + background: u\rl("//example.org/picture.jpg"); + height: ca\lc(100% - 1px); +} \ No newline at end of file