From 34dbad55c589b8c1f3c3fc1eadfb88d989516695 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Mon, 21 Jun 2010 01:35:25 +0000 Subject: #444228 follow-up by Tri, ridgerunner, Damien Tournoud, et al: Improve Optimize CSS performance by removing support for Mac IE 5.5 comment hacks, and add tests. (Apologies; some of this went in with a previous commit http://drupal.org/cvs?commit=382522) --- includes/common.inc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'includes') diff --git a/includes/common.inc b/includes/common.inc index 639861cd9..a170ee1bb 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -3266,14 +3266,21 @@ function drupal_load_stylesheet_content($contents, $optimize = FALSE) { if ($optimize) { // Perform some safe CSS optimizations. - $contents = preg_replace('{ - (?<=\\\\\*/)([^/\*]+/\*)([^\*/]+\*/) # Add a backslash also at the end ie-mac hack comment, so the next pass will not touch it. - # The added backslash does not affect the effectiveness of the hack. - }x', '\1\\\\\2', $contents); - $contents = preg_replace('< - \s*([@{}:;,]|\)\s|\s\()\s* | # Remove whitespace around separators, but keep space around parentheses. - /\*[^*\\\\]*\*+([^/*][^*]*\*+)*/ | # Remove comments that are not CSS hacks. - >x', '\1', $contents); + // Regexp to match comment blocks. + $comment = '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/'; + // Regexp to match double quoted strings. + $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; + // Regexp to match single quoted strings. + $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"; + $contents = preg_replace( + "<($double_quot|$single_quot)|$comment>Sus", // Strip all comment blocks + "$1", // but keep double/single + $contents); // quoted strings. + $contents = preg_replace( + '<\s*([@{}:;,]|\)\s|\s\()\s*>S', // Remove whitespace around separators, + '\1', $contents); // but keep space around parentheses. + // End the file with a new line. + $contents .= "\n"; } // Replaces @import commands with the actual stylesheet content. -- cgit v1.2.3