Skip to content

Commit 50a802f

Browse files
authored
Merge pull request MyIntervals#111 from moodlehq/ms-filter-parsing
Parsing of filter rules specific to Microsoft
2 parents 850cbbc + ed580dc commit 50a802f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ private function parsePrimitiveValue() {
436436
$oValue = $this->parseURLValue();
437437
} else if ($this->comes("'") || $this->comes('"')) {
438438
$oValue = $this->parseStringValue();
439+
} else if ($this->comes("progid:") && $this->oParserSettings->bLenientParsing) {
440+
$oValue = $this->parseMicrosoftFilter();
439441
} else {
440442
$oValue = $this->parseIdentifier(true, false);
441443
}
@@ -496,6 +498,12 @@ private function parseColorValue() {
496498
return new Color($aColor, $this->iLineNo);
497499
}
498500

501+
private function parseMicrosoftFilter() {
502+
$sFunction = $this->consumeUntil('(', false, true);
503+
$aArguments = $this->parseValue(array(',', '='));
504+
return new CSSFunction($sFunction, $aArguments, ',', $this->iLineNo);
505+
}
506+
499507
private function parseURLValue() {
500508
$bUseUrl = $this->comes('url', true);
501509
if ($bUseUrl) {

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,4 +582,17 @@ function testTopLevelCommentExtracting() {
582582
$this->assertCount(1, $comments);
583583
$this->assertEquals("Find Me!", $comments[0]->getComment());
584584
}
585+
586+
/**
587+
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
588+
*/
589+
function testMicrosoftFilterStrictParsing() {
590+
$oDoc = $this->parsedStructureForFile('ms-filter', Settings::create()->beStrict());
591+
}
592+
593+
function testMicrosoftFilterParsing() {
594+
$oDoc = $this->parsedStructureForFile('ms-filter');
595+
$sExpected = ".test {filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\"#80000000\",endColorstr=\"#00000000\",GradientType=1);}";
596+
$this->assertSame($sExpected, $oDoc->render());
597+
}
585598
}

tests/files/ms-filter.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.test {filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#00000000', GradientType=1);}

0 commit comments

Comments
 (0)