From d537fef2f4c09ae54facb83d0e37829939e56acc Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 20 Jan 2021 11:59:47 +0100 Subject: [PATCH] Fixes #1125 - quotes incorrectly stripped from `@supports` clause. --- History.md | 1 + lib/optimizer/level-1/tidy-block.js | 7 +++++-- test/integration-test.js | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 7be1dba9b..02986b1da 100644 --- a/History.md +++ b/History.md @@ -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) diff --git a/lib/optimizer/level-1/tidy-block.js b/lib/optimizer/level-1/tidy-block.js index 8322aeca7..cb097dff3 100644 --- a/lib/optimizer/level-1/tidy-block.js +++ b/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, ')'); } diff --git a/test/integration-test.js b/test/integration-test.js index b2119c15e..311adcbd3 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -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}'