Skip to content

Commit

Permalink
Merge pull request #127 from mdio/master
Browse files Browse the repository at this point in the history
Added @charset removal to doCleanup() to fix processing stylesheets with @charset
  • Loading branch information
tijsverkoyen authored Jul 20, 2016
2 parents 2ebaccb + 448a1df commit b081b74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Css/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 20 additions & 0 deletions tests/Css/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ public function testMakeSureMediaQueriesAreRemoved()
$this->assertEmpty($this->processor->getRules($css));
}

public function testCssWithCharset()
{
$css = <<<EOF
@charset "UTF-8";
a {
color: red;
}
EOF;

$rules = $this->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";
Expand Down

0 comments on commit b081b74

Please sign in to comment.