diff --git a/core/lib/Drupal/Core/Asset/CssOptimizer.php b/core/lib/Drupal/Core/Asset/CssOptimizer.php index 87575e0..99fdbc1 100644 --- a/core/lib/Drupal/Core/Asset/CssOptimizer.php +++ b/core/lib/Drupal/Core/Asset/CssOptimizer.php @@ -205,8 +205,10 @@ protected function processCss($contents, $optimize = FALSE) { // whitespace. // @see http://php.net/manual/regexp.reference.subpatterns.php $contents = preg_replace('< + # Do not strip any space from within single or double quotes + ('.$double_quot.'|'.$single_quot.') # Strip leading and trailing whitespace. - \s*([@{};,])\s* + | \s*([@{};,])\s* # Strip only leading whitespace from: # - Closing parenthesis: Retain "@media (bar) and foo". | \s+([\)]) @@ -214,11 +216,11 @@ protected function processCss($contents, $optimize = FALSE) { # - Opening parenthesis: Retain "@media (bar) and foo". # - Colon: Retain :pseudo-selectors. | ([\(:])\s+ - >xS', - // Only one of the three capturing groups will match, so its reference + >xSs', + // Only one of the four capturing groups will match, so its reference // will contain the wanted value and the references for the // two non-matching groups will be replaced with empty strings. - '$1$2$3', + '$1$2$3$4', $contents ); // End the file with a new line. diff --git a/core/tests/Drupal/Tests/Core/Asset/css_test_files/quotes.css b/core/tests/Drupal/Tests/Core/Asset/css_test_files/quotes.css new file mode 100644 index 0000000..3fe0f7d --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Asset/css_test_files/quotes.css @@ -0,0 +1,31 @@ +/* Example from https://www.w3.org/TR/CSS2/syndata.html#rule-sets */ +q[example="public class foo\ +{\ + private int x;\ +\ + foo(int x) {\ + this.x = x;\ + }\ +\ +}"] { color: red } + +/* A pseudo selector with essential whitespace wrapped in quotes. */ +q[style*="quotes: none"] { + quotes: none; +} + +q[style*='quotes: none'] { + quotes: none; +} + +q:after { + content: ": colon & escaped double \" quotes \"."; +} + +q:after { + content: ' (brackets & escaped single \' quotes \') '; +} + +q:after { + content: "I'm Quote"; +} diff --git a/core/tests/Drupal/Tests/Core/Asset/css_test_files/quotes.css.optimized.css b/core/tests/Drupal/Tests/Core/Asset/css_test_files/quotes.css.optimized.css new file mode 100644 index 0000000..716cef7 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Asset/css_test_files/quotes.css.optimized.css @@ -0,0 +1,9 @@ +q[example="public class foo\ +{\ + private int x;\ +\ + foo(int x) {\ + this.x = x;\ + }\ +\ +}"]{color:red}q[style*="quotes: none"]{quotes:none;}q[style*='quotes: none']{quotes:none;}q:after{content:": colon & escaped double \" quotes \".";}q:after{content:' (brackets & escaped single \' quotes \') ';}q:after{content:"I'm Quote";}