summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-10-08 15:36:12 +0000
committerDries Buytaert <dries@buytaert.net>2010-10-08 15:36:12 +0000
commit7faedbdd5f9d65058463274c7b5a408e15934063 (patch)
tree88547593bd0cc76ca99da2162e871c36ed97bad0
parent17d30dc3a37c9eb524d601a34004efc92322d984 (diff)
downloadbrdo-7faedbdd5f9d65058463274c7b5a408e15934063.tar.gz
brdo-7faedbdd5f9d65058463274c7b5a408e15934063.tar.bz2
- Patch #460448 by sun: some CSS rules are broken once CSS aggregation is enabled.
-rw-r--r--includes/common.inc33
-rw-r--r--modules/simpletest/files/css_test_files/css_input_without_import.css38
-rw-r--r--modules/simpletest/files/css_test_files/css_input_without_import.css.optimized.css2
-rw-r--r--modules/simpletest/files/css_test_files/css_input_without_import.css.unoptimized.css38
-rw-r--r--modules/simpletest/tests/common.test15
5 files changed, 108 insertions, 18 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 3c6d28423..bab8b1e82 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3463,13 +3463,34 @@ function drupal_load_stylesheet_content($contents, $optimize = FALSE) {
$double_quot = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
// Regexp to match single quoted strings.
$single_quot = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
+ // Strip all comment blocks, but keep double/single quoted strings.
$contents = preg_replace(
- "<($double_quot|$single_quot)|$comment>Ss", // 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.
+ "<($double_quot|$single_quot)|$comment>Ss",
+ "$1",
+ $contents
+ );
+ // Remove certain whitespace.
+ // There are different conditions for removing leading and trailing
+ // whitespace. To be able to use a single backreference in the replacement
+ // string, the outer pattern uses the ?| modifier, which makes all contained
+ // subpatterns appear in \1.
+ // @see http://php.net/manual/en/regexp.reference.subpatterns.php
+ $contents = preg_replace('<
+ (?|
+ # Strip leading and trailing whitespace.
+ \s*([@{};,])\s*
+ # Strip only leading whitespace from:
+ # - Closing parenthesis: Retain "@media (bar) and foo".
+ | \s+([\)])
+ # Strip only trailing whitespace from:
+ # - Opening parenthesis: Retain "@media (bar) and foo".
+ # - Colon: Retain :pseudo-selectors.
+ | ([\(:])\s+
+ )
+ >xS',
+ '\1',
+ $contents
+ );
// End the file with a new line.
$contents .= "\n";
}
diff --git a/modules/simpletest/files/css_test_files/css_input_without_import.css b/modules/simpletest/files/css_test_files/css_input_without_import.css
index 89e2df24c..49eb1eef3 100644
--- a/modules/simpletest/files/css_test_files/css_input_without_import.css
+++ b/modules/simpletest/files/css_test_files/css_input_without_import.css
@@ -19,10 +19,9 @@ body {
}
/**
- * CSS spec says that all whitespace is valid whitespace, so this selector should be just as
- * good as the one above.
+ * CSS spec says that all whitespace is valid whitespace, so this selector
+ * should be just as good as the one above.
*/
-
.this
.is
.a
@@ -31,6 +30,39 @@ font: 1em/100% Verdana, sans-serif;
color: #494949;
}
+some :pseudo .thing {
+ -moz-border-radius: 3px;
+ -webkit-border-radius: 3px;
+ border-radius: 3px;
+ filter: progid:DXImageTransform.Microsoft.Shadow(color=#000000, direction='180', strength='10');
+ -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(color=#000000, direction='180', strength='10')";
+}
+
+::-moz-selection {
+ background: #000;
+ color:#fff;
+
+}
+::selection {
+ background: #000;
+ color: #fff;
+}
+
+@media print {
+ * {
+ background: #000 !important;
+ color: #fff !important;
+ }
+ @page {
+ margin: 0.5cm;
+ }
+}
+
+@media screen and (max-device-width: 480px) {
+ background: #000;
+ color: #fff;
+}
+
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 6a90a8f76..c19251143 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
@@ -6,4 +6,4 @@
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;}
+.test{font:1em/100% Verdana,sans-serif;color:#494949;}some :pseudo .thing{-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;filter:progid:DXImageTransform.Microsoft.Shadow(color=#000000,direction='180',strength='10');-ms-filter:"progid:DXImageTransform.Microsoft.Shadow(color=#000000,direction='180',strength='10')";}::-moz-selection{background:#000;color:#fff;}::selection{background:#000;color:#fff;}@media print{*{background:#000 !important;color:#fff !important;}@page{margin:0.5cm;}}@media screen and (max-device-width:480px){background:#000;color:#fff;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;}
diff --git a/modules/simpletest/files/css_test_files/css_input_without_import.css.unoptimized.css b/modules/simpletest/files/css_test_files/css_input_without_import.css.unoptimized.css
index 89e2df24c..49eb1eef3 100644
--- a/modules/simpletest/files/css_test_files/css_input_without_import.css.unoptimized.css
+++ b/modules/simpletest/files/css_test_files/css_input_without_import.css.unoptimized.css
@@ -19,10 +19,9 @@ body {
}
/**
- * CSS spec says that all whitespace is valid whitespace, so this selector should be just as
- * good as the one above.
+ * CSS spec says that all whitespace is valid whitespace, so this selector
+ * should be just as good as the one above.
*/
-
.this
.is
.a
@@ -31,6 +30,39 @@ font: 1em/100% Verdana, sans-serif;
color: #494949;
}
+some :pseudo .thing {
+ -moz-border-radius: 3px;
+ -webkit-border-radius: 3px;
+ border-radius: 3px;
+ filter: progid:DXImageTransform.Microsoft.Shadow(color=#000000, direction='180', strength='10');
+ -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(color=#000000, direction='180', strength='10')";
+}
+
+::-moz-selection {
+ background: #000;
+ color:#fff;
+
+}
+::selection {
+ background: #000;
+ color: #fff;
+}
+
+@media print {
+ * {
+ background: #000 !important;
+ color: #fff !important;
+ }
+ @page {
+ margin: 0.5cm;
+ }
+}
+
+@media screen and (max-device-width: 480px) {
+ background: #000;
+ color: #fff;
+}
+
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 43f4b5cc1..c63633ee7 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -862,11 +862,10 @@ class CascadingStylesheetsUnitTest extends DrupalUnitTestCase {
/**
* Tests basic CSS loading with and without optimization via drupal_load_stylesheet().
*
- * This can be enhanced by adding additional CSS files with variant test cases.
- * Currently, this is specifically testing to make sure that whitespace
- * is treated with adequate respect (see http://drupal.org/node/472820) and
- * that image paths in imported files are preserved (see
- * http://drupal.org/node/265719).
+ * Known tests:
+ * - Retain white-space in selectors. (http://drupal.org/node/472820)
+ * - Proper URLs in imported files. (http://drupal.org/node/265719)
+ * - Retain pseudo-selectors. (http://drupal.org/node/460448)
*/
function testLoadCssBasic() {
// Array of files to test living in 'simpletest/files/css_test_files/'.
@@ -882,10 +881,16 @@ class CascadingStylesheetsUnitTest extends DrupalUnitTestCase {
foreach ($testfiles as $file) {
$expected = file_get_contents("$path/$file.unoptimized.css");
$unoptimized_output = drupal_load_stylesheet("$path/$file.unoptimized.css", FALSE);
+ $this->verbose('Expected:<pre>' . $expected . '</pre>'
+ . 'Actual:<pre>' . $unoptimized_output . '</pre>'
+ );
$this->assertEqual($unoptimized_output, $expected, t('Unoptimized CSS file has expected contents (@file)', array('@file' => $file)));
$expected = file_get_contents("$path/$file.optimized.css");
$optimized_output = drupal_load_stylesheet("$path/$file", TRUE);
+ $this->verbose('Expected:<pre>' . $expected . '</pre>'
+ . 'Actual:<pre>' . $optimized_output . '</pre>'
+ );
$this->assertEqual($optimized_output, $expected, t('Optimized CSS file has expected contents (@file)', array('@file' => $file)));
}
}