From 448a1df7a9eff96b847cfc144549211f731863a1 Mon Sep 17 00:00:00 2001 From: Michael Diodone Date: Wed, 2 Mar 2016 09:46:18 +0100 Subject: [PATCH] Added @charset removal to doCleanup() to fix processing stylesheets with @charset --- src/Css/Processor.php | 2 ++ tests/Css/ProcessorTest.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Css/Processor.php b/src/Css/Processor.php index c3af3d2..4d943d9 100644 --- a/src/Css/Processor.php +++ b/src/Css/Processor.php @@ -49,6 +49,8 @@ public function getCssFromStyleTags($html) */ private function doCleanup($css) { + // remove charset + $css = preg_replace('/@charset "[^"]+";/', '', $css); // remove media queries $css = preg_replace('/@media [^{]*{([^{}]|{[^{}]*})*}/', '', $css); diff --git a/tests/Css/ProcessorTest.php b/tests/Css/ProcessorTest.php index f286da5..0578242 100644 --- a/tests/Css/ProcessorTest.php +++ b/tests/Css/ProcessorTest.php @@ -87,6 +87,26 @@ public function testMakeSureMediaQueriesAreRemoved() $this->assertEmpty($this->processor->getRules($css)); } + public function testCssWithCharset() + { + $css = <<processor->getRules($css); + + $this->assertCount(1, $rules); + $this->assertInstanceOf('TijsVerkoyen\CssToInlineStyles\Css\Rule\Rule', $rules[0]); + $this->assertEquals('a', $rules[0]->getSelector()); + $this->assertCount(1, $rules[0]->getProperties()); + $this->assertEquals('color', $rules[0]->getProperties()[0]->getName()); + $this->assertEquals('red', $rules[0]->getProperties()[0]->getValue()); + $this->assertEquals(1, $rules[0]->getOrder()); + } + public function testSimpleStyleTagsInHtml() { $expected = 'p { color: #F00; }' . "\n";