summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/common.inc23
-rw-r--r--modules/simpletest/files/css_test_files/css_input_with_import.css.optimized.css6
-rw-r--r--modules/simpletest/files/css_test_files/css_input_without_import.css.optimized.css6
-rw-r--r--modules/simpletest/tests/common.test7
4 files changed, 25 insertions, 17 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.
diff --git a/modules/simpletest/files/css_test_files/css_input_with_import.css.optimized.css b/modules/simpletest/files/css_test_files/css_input_with_import.css.optimized.css
index 60006c583..96fb99314 100644
--- a/modules/simpletest/files/css_test_files/css_input_with_import.css.optimized.css
+++ b/modules/simpletest/files/css_test_files/css_input_with_import.css.optimized.css
@@ -1,6 +1,8 @@
ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(images/icon.png);}
-p,select{font:1em/160% Verdana,sans-serif;color:#494949;}body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}.this
+
+p,select{font:1em/160% Verdana,sans-serif;color:#494949;}
+body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}.this
.is
.a
-.test{font:1em/100% Verdana,sans-serif;color:#494949;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;} \ No newline at end of file
+.test{font:1em/100% Verdana,sans-serif;color:#494949;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;}
diff --git a/modules/simpletest/files/css_test_files/css_input_without_import.css.optimized.css b/modules/simpletest/files/css_test_files/css_input_without_import.css.optimized.css
index e5920f094..6a90a8f76 100644
--- a/modules/simpletest/files/css_test_files/css_input_without_import.css.optimized.css
+++ b/modules/simpletest/files/css_test_files/css_input_without_import.css.optimized.css
@@ -3,9 +3,7 @@
-body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}
-
-.this
+body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}.this
.is
.a
-.test{font:1em/100% Verdana,sans-serif;color:#494949;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;} \ No newline at end of file
+.test{font:1em/100% Verdana,sans-serif;color:#494949;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;}
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index cb29f58b4..53fb5704f 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -101,13 +101,13 @@ class CommonURLUnitTest extends DrupalWebTestCase {
$class = $this->randomName();
$link = l($this->randomName(), $_GET['q'], array('attributes' => array('class' => array($class))));
$this->assertTrue($this->hasClass($link, $class), t('Custom class @class is present on link when requested', array('@class' => $class)));
- $this->assertTrue($this->hasClass($link, 'active'), t('Class @class is present on link to the current page', array('@class' => 'active')));
+ $this->assertTrue($this->hasClass($link, 'active'), t('Class @class is present on link to the current page', array('@class' => 'active')));
}
private function hasClass($link, $class) {
return preg_match('|class="([^\"\s]+\s+)*' . $class . '|', $link);
}
-
+
/**
* Test drupal_get_query_parameters().
*/
@@ -811,7 +811,8 @@ class CascadingStylesheetsUnitTest extends DrupalUnitTestCase {
// - Optimized expected content: name.css.optimized.css
$testfiles = array(
'css_input_without_import.css',
- 'css_input_with_import.css'
+ 'css_input_with_import.css',
+ 'comment_hacks.css'
);
$path = drupal_get_path('module', 'simpletest') . '/files/css_test_files';
foreach ($testfiles as $file) {