comparison core/lib/Drupal/Core/Asset/CssOptimizer.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
117 $content = ''; 117 $content = '';
118 if ($contents = @file_get_contents($file)) { 118 if ($contents = @file_get_contents($file)) {
119 // If a BOM is found, convert the file to UTF-8, then use substr() to 119 // If a BOM is found, convert the file to UTF-8, then use substr() to
120 // remove the BOM from the result. 120 // remove the BOM from the result.
121 if ($encoding = (Unicode::encodingFromBOM($contents))) { 121 if ($encoding = (Unicode::encodingFromBOM($contents))) {
122 $contents = Unicode::substr(Unicode::convertToUtf8($contents, $encoding), 1); 122 $contents = mb_substr(Unicode::convertToUtf8($contents, $encoding), 1);
123 } 123 }
124 // If no BOM, check for fallback encoding. Per CSS spec the regex is very strict. 124 // If no BOM, check for fallback encoding. Per CSS spec the regex is very strict.
125 elseif (preg_match('/^@charset "([^"]+)";/', $contents, $matches)) { 125 elseif (preg_match('/^@charset "([^"]+)";/', $contents, $matches)) {
126 if ($matches[1] !== 'utf-8' && $matches[1] !== 'UTF-8') { 126 if ($matches[1] !== 'utf-8' && $matches[1] !== 'UTF-8') {
127 $contents = substr($contents, strlen($matches[0])); 127 $contents = substr($contents, strlen($matches[0]));
187 $contents = $this->clean($contents); 187 $contents = $this->clean($contents);
188 188
189 if ($optimize) { 189 if ($optimize) {
190 // Perform some safe CSS optimizations. 190 // Perform some safe CSS optimizations.
191 // Regexp to match comment blocks. 191 // Regexp to match comment blocks.
192 $comment = '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/'; 192 $comment = '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/';
193 // Regexp to match double quoted strings. 193 // Regexp to match double quoted strings.
194 $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; 194 $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
195 // Regexp to match single quoted strings. 195 // Regexp to match single quoted strings.
196 $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"; 196 $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
197 // Strip all comment blocks, but keep double/single quoted strings. 197 // Strip all comment blocks, but keep double/single quoted strings.