Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.611.2.26 diff -u -p -r1.611.2.26 common.inc --- includes/common.inc 4 Mar 2010 00:16:02 -0000 1.611.2.26 +++ includes/common.inc 21 Jun 2010 05:51:02 -0000 @@ -1685,11 +1685,21 @@ 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); + // Regexp to match comment blocks. + $comment = '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/'; + // Regexp to match double quoted strings. + $double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'; + // Regexp to match single quoted strings. + $single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"; + $data = preg_replace_callback( + "<$double_quot|$single_quot|$comment>Sus", // Match all comment blocks along + "_process_comment", // with double/single quoted strings + $data); // and feed them to _process_comment(). + $data = preg_replace( + '<\s*([@{}:;,]|\)\s|\s\()\s*>S', // Remove whitespace around separators, + '\1', $data); // but keep space around parentheses. + // End the file with a new line. + $data .= "\n"; // Create the CSS file. file_save_data($data, $csspath .'/'. $filename, FILE_EXISTS_REPLACE); @@ -1698,6 +1708,41 @@ function drupal_build_css_cache($types, } /** + * Process comment blocks. + * + * 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. + if ($matches[0][0] == "'" || $matches[0][0] == '"') { + return $matches[0]; + } + // End of IE-Mac hack, keep it. + if ($keep_nextone) { + $keep_nextone = FALSE; + return $matches[0]; + } + switch (strrpos($matches[0], '\\')) { + case FALSE : + // No backslash, strip it. + return ''; + + case drupal_strlen($matches[0])-3 : + // Ends with \*/ so is a multi line IE-Mac hack, keep the next one also. + $keep_nextone = TRUE; + return '/*_\*/'; + + default : + // Single line IE-Mac hack. + return '/*\_*/'; + } +} + +/** * Delete all cached CSS files. */ function drupal_clear_css_cache() {