diff options
-rw-r--r-- | includes/common.inc | 2 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/includes/common.inc b/includes/common.inc index a64f0c555..9ad68eabd 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -3700,7 +3700,7 @@ function drupal_load_stylesheet($file, $optimize = NULL, $reset_basepath = TRUE) */ function drupal_load_stylesheet_content($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. diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 8694ff32e..856945f63 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -687,6 +687,31 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase { } /** + * Tests removing charset when rendering stylesheets with preprocessing on. + */ + function testRenderRemoveCharsetPreprocess() { + $cases = array( + array( + 'asset' => '@charset "UTF-8";html{font-family:"sans-serif";}', + 'expected' => 'html{font-family:"sans-serif";}', + ), + // This asset contains extra \n character. + array( + 'asset' => "@charset 'UTF-8';\nhtml{font-family:'sans-serif';}", + 'expected' => "\nhtml{font-family:'sans-serif';}", + ), + ); + + foreach ($cases as $case) { + $this->assertEqual( + $case['expected'], + drupal_load_stylesheet_content($case['asset']), + 'CSS optimizing correctly removes the charset declaration.' + ); + } + } + + /** * Tests rendering inline stylesheets with preprocessing off. */ function testRenderInlineNoPreprocess() { |