Skip to content

Commit

Permalink
Fixes #1125 - quotes incorrectly stripped from @supports clause.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubpawlowicz committed Jan 20, 2021
1 parent c873d7d commit d537fef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -12,6 +12,7 @@
* Fixed issue [#1087](https://github.com/jakubpawlowicz/clean-css/issues/1087) - allow units with any case.
* Fixed issue [#1117](https://github.com/jakubpawlowicz/clean-css/issues/1117) - don't change zero values inside `min`, `max`, and `clamp` functions.
* Fixed issue [#1122](https://github.com/jakubpawlowicz/clean-css/issues/1122) - don't wrap data URI in single quotes.
* Fixed issue [#1125](https://github.com/jakubpawlowicz/clean-css/issues/1125) - quotes stripped from withing `@supports` clause.
* Reworks all level 1 optimizations to conform to plugin style.

[4.2.3 / 2020-01-28](https://github.com/jakubpawlowicz/clean-css/compare/v4.2.2...v4.2.3)
Expand Down
7 changes: 5 additions & 2 deletions lib/optimizer/level-1/tidy-block.js
@@ -1,19 +1,22 @@
var SUPPORTED_COMPACT_BLOCK_MATCHER = /^@media\W/;
var SUPPORTED_QUOTE_REMOVAL_MATCHER = /^@(?:keyframes|-moz-keyframes|-o-keyframes|-webkit-keyframes)\W/;

function tidyBlock(values, spaceAfterClosingBrace) {
var withoutSpaceAfterClosingBrace;
var withoutQuotes;
var i;

for (i = values.length - 1; i >= 0; i--) {
withoutSpaceAfterClosingBrace = !spaceAfterClosingBrace && SUPPORTED_COMPACT_BLOCK_MATCHER.test(values[i][1]);
withoutQuotes = SUPPORTED_QUOTE_REMOVAL_MATCHER.test(values[i][1]);

values[i][1] = values[i][1]
.replace(/\n|\r\n/g, ' ')
.replace(/\s+/g, ' ')
.replace(/(,|:|\() /g, '$1')
.replace(/ \)/g, ')')
.replace(/'([a-zA-Z][a-zA-Z\d\-_]+)'/, '$1')
.replace(/"([a-zA-Z][a-zA-Z\d\-_]+)"/, '$1')
.replace(withoutQuotes ? /'([a-zA-Z][a-zA-Z\d\-_]+)'/ : null, '$1')
.replace(withoutQuotes ? /"([a-zA-Z][a-zA-Z\d\-_]+)"/ : null, '$1')
.replace(withoutSpaceAfterClosingBrace ? /\) /g : null, ')');
}

Expand Down
4 changes: 4 additions & 0 deletions test/integration-test.js
Expand Up @@ -2441,6 +2441,10 @@ vows.describe('integration tests')
'@supports (display:flexbox){.flex{display:flexbox}}',
'@supports (display:flexbox){.flex{display:flexbox}}'
],
'@supports with quoted text': [
'@supports (font-feature-settings:"liga" 0){html{--font:"font-with-features",helvetica,sans-serif}}',
'@supports (font-feature-settings:"liga" 0){html{--font:"font-with-features",helvetica,sans-serif}}'
],
'@-ms-viewport': [
'@-ms-viewport{width:device-width}',
'@-ms-viewport{width:device-width}'
Expand Down

0 comments on commit d537fef

Please sign in to comment.