Commit 1baad8a5 authored by alexpott's avatar alexpott

Issue #2040209 by WebEvt: Fixed CSS is truncated when aggregation is turned on.

parent 44c83898
......@@ -161,7 +161,7 @@ protected function loadNestedFile($matches) {
*/
protected function processCss($contents, $optimize = FALSE) {
// Remove multiple charset declarations for standards compliance (and fixing Safari problems).
$contents = preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents);
$contents = preg_replace('/^@charset\s+[\'"](\S*?)\b[\'"];/i', '', $contents);
if ($optimize) {
// Perform some safe CSS optimizations.
......
......@@ -200,6 +200,38 @@ function testOptimize($css_asset, $expected) {
$this->assertEquals($expected, $this->optimizer->optimize($css_asset), 'Group of file CSS assets optimized correctly.');
}
/**
* Tests optimizing a CSS asset containing charset declaration.
*/
function testOptimizeRemoveCharset() {
$cases = array(
array(
'asset' => array(
'type' => 'inline',
'data' => '@charset "UTF-8";html{font-family:"sans-serif";}',
'preprocess' => FALSE,
),
'expected' => 'html{font-family:"sans-serif";}',
),
array(
// This asset contains extra \n character.
'asset' => array(
'type' => 'inline',
'data' => "@charset 'UTF-8';\nhtml{font-family:'sans-serif';}",
'preprocess' => FALSE,
),
'expected' => "\nhtml{font-family:'sans-serif';}",
),
);
foreach ($cases as $case) {
$this->assertEquals(
$case['expected'],
$this->optimizer->optimize($case['asset']),
'CSS optimizing correctly removes the charset declaration.'
);
}
}
/**
* Tests a file CSS asset with preprocessing disabled.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment