Fixes #843 - more restrictive quote removal rules.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 17 Dec 2016 11:54:27 +0000 (12:54 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 17 Dec 2016 12:00:01 +0000 (13:00 +0100)
Why:

* Only remove quotes from selector argument values if allowed.

History.md
lib/optimizer/tidy-rules.js
test/fixtures/bootstrap-min.css
test/optimizer/basic-test.js

index 7ad4360..3589091 100644 (file)
@@ -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)
 ==================
index 745b4d4..c3cd31e 100644 (file)
@@ -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) {
index 111cfbf..84c5382 100644 (file)
@@ -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}
index 1f4931a..7d05c40 100644 (file)
@@ -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 })
   )