From: Jakub Pawlowicz Date: Sat, 17 Dec 2016 11:54:27 +0000 (+0100) Subject: Fixes #843 - more restrictive quote removal rules. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f84589102aecfeb8189877f9228cca152f3f0063;p=clean-css.git Fixes #843 - more restrictive quote removal rules. Why: * Only remove quotes from selector argument values if allowed. --- diff --git a/History.md b/History.md index 7ad43609..35890919 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ * Replaces the old tokenizer with a new one which doesn't use any escaping. * Replaces the old `@import` inlining with one on top of the new tokenizer. * Simplifies URL rebasing with a single `rebaseTo` option in API or inferred from `--output` in CLI. +* Fixed issue [#843](https://github.com/jakubpawlowicz/clean-css/issues/843) - regression in selector handling. [3.4.22 / 2016-12-12](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.21...v3.4.22) ================== diff --git a/lib/optimizer/tidy-rules.js b/lib/optimizer/tidy-rules.js index 745b4d4d..c3cd31e2 100644 --- a/lib/optimizer/tidy-rules.js +++ b/lib/optimizer/tidy-rules.js @@ -129,8 +129,8 @@ function removeWhitespace(value) { function removeQuotes(value) { return value - .replace(/([^\[])'([a-zA-Z][a-zA-Z\d\-_]+)([^\]])'/g, '$1$2$3') - .replace(/([^\[])"([a-zA-Z][a-zA-Z\d\-_]+)([^\]])"/g, '$1$2$3'); + .replace(/='([a-zA-Z][a-zA-Z\d\-_]+)'/g, '=$1') + .replace(/="([a-zA-Z][a-zA-Z\d\-_]+)"/g, '=$1'); } function ruleSorter(s1, s2) { diff --git a/test/fixtures/bootstrap-min.css b/test/fixtures/bootstrap-min.css index 111cfbf8..84c5382b 100644 --- a/test/fixtures/bootstrap-min.css +++ b/test/fixtures/bootstrap-min.css @@ -39,7 +39,7 @@ td,th{padding:0} a,a:visited{text-decoration:underline} a[href]:after{content:" (" attr(href) ")"} abbr[title]:after{content:" (" attr(title) ")"} -a[href^="#"]:after,a[href^=javascript:]:after{content:""} +a[href^="#"]:after,a[href^="javascript:"]:after{content:""} blockquote,pre{border:1px solid #999} thead{display:table-header-group} img{max-width:100%!important} diff --git a/test/optimizer/basic-test.js b/test/optimizer/basic-test.js index 1f4931a7..7d05c40f 100644 --- a/test/optimizer/basic-test.js +++ b/test/optimizer/basic-test.js @@ -96,6 +96,10 @@ vows.describe('simple optimizations') 'quotes #1': [ '.a[title="a b c\'s d e f"]{color:red}', '.a[title="a b c\'s d e f"]{color:red}' + ], + 'quotes #2': [ + '.b[data-json=\'"aaaa":"bbbb"\']{color:red}', + '.b[data-json=\'"aaaa":"bbbb"\']{color:red}' ] }, { advanced: false }) )