Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1113 diff -u -p -r1.1113 common.inc --- includes/common.inc 18 Feb 2010 06:28:08 -0000 1.1113 +++ includes/common.inc 20 Feb 2010 08:58:18 -0000 @@ -2954,16 +2954,70 @@ function drupal_load_stylesheet_content( 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); + $contents = str_replace("\r", '', $contents); // Strip any and all carriage returns. + // Match and process strings, comments and everything else, one chunk at a time. + // To understand this regex, read: "Mastering Regular Expressions 3rd Edition" chapter 6. + $contents = preg_replace_callback('% + # One-regex-to-rule-them-all! - version: 20100220_0100 + # Group 1: Match a double quoted string. + ("[^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+") | # or... + # Group 2: Match a single quoted string. + (\'[^\'\\\\]*+(?:\\\\.[^\'\\\\]*+)*+\') | # or... + # Group 3: Match a regular non-MacIE5-hack comment. + (/\*[^\\\\*]*+\*++(?:[^\\\\*/][^\\\\*]*+\*++)*+/) | # or... + # Group 4: Match a MacIE5-type1 comment. + (/\*(?:[^*\\\\]*+\**+(?!/))*+\\\\[^*]*+\*++(?:[^*/][^*]*+\*++)*+/(?{};,)])/S', '$1', $matches[6]); // Clean pre-punctuation. + $matches[6] = preg_replace('/([+>{}:;,(])\s++/S', '$1', $matches[6]); // Clean post-punctuation. + $matches[6] = preg_replace('/;?\}/S', "}\n", $matches[6]); // Add a touch of formatting. + return "\n/*T2\\*/" . $matches[6] . "\n/*T2E*/\n"; // Minify and reassemble composite type2 comment. + } + elseif (isset($matches[8])) { // Group 8: Non-string, non-comment. Safe to clean whitespace here. + $matches[8] = preg_replace('/^\s++/', '', $matches[8]); // Strip all leading whitespace. + $matches[8] = preg_replace('/\s++$/', '', $matches[8]); // Strip all trailing whitespace. + $matches[8] = preg_replace('/\s{2,}+/', ' ', $matches[8]); // Consolidate multiple whitespace. + $matches[8] = preg_replace('/\s++([+>{};,)])/S', '$1', $matches[8]); // Clean pre-punctuation. + $matches[8] = preg_replace('/([+>{}:;,(])\s++/S', '$1', $matches[8]); // Clean post-punctuation. + $matches[8] = preg_replace('/;?\}/S', "}\n", $matches[8]); // Add a touch of formatting. + return $matches[8]; + } + return $matches[0] . "\n/* ERROR! Unexpected _proccess_css_minify() parameter */\n"; // never get here +} + // Replaces @import commands with the actual stylesheet content. // This happens recursively but omits external files. $contents = preg_replace_callback('/@import\s*(?:url\()?[\'"]?(?![a-z]+:)([^\'"\()]+)[\'"]?\)?;/', '_drupal_load_stylesheet', $contents);