From 822d6b22f5208fee6349f9a3c58a44b5ba5fc253 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 17 Nov 2020 15:17:49 +0100 Subject: [PATCH] Place the `@charset` at the very beginning of the generated CSS (#3726) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Place the `@charset` at the very beginning of the generated CSS * Apply suggestions from code review Co-authored-by: Tim Düsterhus Co-authored-by: Tim Düsterhus --- .../files/lib/system/style/StyleCompiler.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index 947bb26304..b11be61278 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -153,7 +153,8 @@ class StyleCompiler extends SingletonFactory { $variables, $individualScss . (!empty($parameters['scss']) ? "\n" . $parameters['scss'] : ''), function($content) use ($styleName) { - return "/* stylesheet for '". $styleName ."', generated on ".gmdate('r')." -- DO NOT EDIT */\n\n" . $content; + $header = "/* stylesheet for '".$styleName."', generated on ".gmdate('r')." -- DO NOT EDIT */"; + return '@charset "UTF-8";' . "\n\n{$header}\n\n" . preg_replace('~^@charset "UTF-8";\r?\n~', '', $content); } ); } @@ -250,7 +251,8 @@ class StyleCompiler extends SingletonFactory { $variables, $individualScss . (!empty($parameters['scss']) ? "\n" . $parameters['scss'] : ''), function($content) use ($style) { - return "/* stylesheet for '".$style->styleName."', generated on ".gmdate('r')." -- DO NOT EDIT */\n\n" . $content; + $header = "/* stylesheet for '".$style->styleName."', generated on ".gmdate('r')." -- DO NOT EDIT */"; + return '@charset "UTF-8";' . "\n\n{$header}\n\n" . preg_replace('~^@charset "UTF-8";\r?\n~', '', $content); } ); } @@ -305,7 +307,8 @@ class StyleCompiler extends SingletonFactory { $content = str_replace('../icon/', '../../icon/', $content); $content = preg_replace('~\.\./images/~', '../../images/', $content); - return "/* stylesheet for ACP, generated on ".gmdate('r')." -- DO NOT EDIT */\n\n" . $content; + $header = "/* stylesheet for the admin panel, generated on ".gmdate('r')." -- DO NOT EDIT */"; + return '@charset "UTF-8";' . "\n\n{$header}\n\n" . preg_replace('~^@charset "UTF-8";\r?\n~', '', $content); } ); } -- 2.20.1