Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.756.2.77 diff -u -p -r1.756.2.77 common.inc --- includes/common.inc 1 Feb 2010 17:44:17 -0000 1.756.2.77 +++ includes/common.inc 21 Feb 2010 02:06:44 -0000 @@ -2007,10 +2007,16 @@ function drupal_load_stylesheet($file, $ if ($_optimize) { // Perform some safe CSS optimizations. - $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); + $comment = '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/'; // Regexp to match comment blocks. + $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; // Regexp to match double quoted strings. + $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"; // Regexp to match single quoted strings. + $contents = preg_replace_callback( + "<$double_quot|$single_quot|$comment>Sus", // Match all comment blocks along with double/single quoted strings and feed them to _process_comment(). + "_process_comment", + $contents); + $contents = preg_replace( + '<\s*([@{}:;,]|\)\s|\s\()\s*>S', // Remove whitespace around separators, but keep space around parentheses. + '\1', $contents); } // Change back directory. @@ -2021,6 +2027,41 @@ function drupal_load_stylesheet($file, $ } /** + * Implements comment strip logic. + * + * This is the callback function for the preg_replace_callback() used in + * drupal_load_stylesheet_content(). Support for comment hacks is implemented here. + */ +function _process_comment($matches) { + static $keep_nextone = FALSE; + // Quoted string, keep it. + $start_char = substr($matches[0], 0, 1); + if ($start_char == "'" || $start_char == '"') { + return $matches[0]; + } + // End of IE-Mac hack, keep it. + if ($keep_nextone) { + $keep_nextone = FALSE; + return $matches[0]; + } + else { + switch (strrpos($matches[0], '\\')) { + // No backslash, strip it. + case FALSE : + return ''; + break; + // Ends with \*/ so is a multi line IE-Mac hack, keep this and the next one. + case drupal_strlen($matches[0])-3 : + $keep_nextone = TRUE; + // Fall through to default case. + // Single line IE-Mac hack, keep this. + default : + return $matches[0]; + } + } +} + +/** * Loads stylesheets recursively and returns contents with corrected paths. * * This function is used for recursive loading of stylesheets and