From: Alexander Ebert Date: Tue, 17 Nov 2020 14:17:49 +0000 (+0100) Subject: Place the `@charset` at the very beginning of the generated CSS (#3726) X-Git-Tag: 5.3.1~28 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=822d6b22f5208fee6349f9a3c58a44b5ba5fc253;p=GitHub%2FWoltLab%2FWCF.git Place the `@charset` at the very beginning of the generated CSS (#3726) * 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 --- 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); } ); }