summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc23
1 files changed, 15 insertions, 8 deletions
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.