Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.611.2.25 diff -u -p -r1.611.2.25 common.inc --- includes/common.inc 16 Sep 2009 17:29:09 -0000 1.611.2.25 +++ includes/common.inc 21 Feb 2010 02:06:27 -0000 @@ -1674,11 +1674,16 @@ function drupal_build_css_cache($types, $data = implode('', $matches[0]) . $data; // Perform some safe CSS optimizations. - $data = preg_replace('< - \s*([@{}:;,]|\)\s|\s\()\s* | # Remove whitespace around separators, but keep space around parentheses. - /\*([^*\\\\]|\*(?!/))+\*/ | # Remove comments that are not CSS hacks. - [\n\r] # Remove line breaks. - >x', '\1', $data); + $comment = '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/'; // Regexp to match comment blocks. + $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; // Regexp to match double quoted strings. + $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"; // Regexp to match single quoted strings. + $data = 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", + $data); + $data = preg_replace( + '<\s*([@{}:;,]|\)\s|\s\()\s*>S', // Remove whitespace around separators, but keep space around parentheses. + '\1', $data); // Create the CSS file. file_save_data($data, $csspath .'/'. $filename, FILE_EXISTS_REPLACE); @@ -1687,6 +1692,41 @@ function drupal_build_css_cache($types, } /** + * 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]; + } + } +} + +/** * Delete all cached CSS files. */ function drupal_clear_css_cache() {