Fixes #155 - broken irregular CSS content.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 26 Oct 2013 09:12:22 +0000 (11:12 +0200)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 26 Oct 2013 09:17:24 +0000 (11:17 +0200)
* ["content"] is an invalid CSS but it was matched as an attribute.
* If placed inside content property value it was matched BEFORE we escape all free text.

History.md
lib/clean.js
test/unit-test.js

index d532f8d..4a394d7 100644 (file)
@@ -3,6 +3,11 @@
 
 * Adds simplified and more advanced text escaping / restoring via `EscapeStore` class.
 
+1.1.6 / 2013-xx-xx
+==================
+
+* Fixed issue [#155](https://github.com/GoalSmashers/clean-css/issues/155) - broken irregular CSS content.
+
 1.1.5 / 2013-10-24
 ==================
 
index 7e1a9c2..7366e60 100644 (file)
@@ -113,7 +113,11 @@ var CleanCSS = {
     // strip parentheses in attribute values
     replace(/\[([^\]]+)\]/g, function(match, content) {
       var eqIndex = content.indexOf('=');
-      if (eqIndex < 0 && content.indexOf('\'') < 0 && content.indexOf('"') < 0)
+      var singleQuoteIndex = content.indexOf('\'');
+      var doubleQuoteIndex = content.indexOf('"');
+      if (eqIndex < 0 && singleQuoteIndex < 0 && doubleQuoteIndex < 0)
+        return match;
+      if (singleQuoteIndex === 0 || doubleQuoteIndex === 0)
         return match;
 
       var key = content.substring(0, eqIndex);
index 64c8743..17d74b1 100644 (file)
@@ -306,7 +306,8 @@ vows.describe('clean-units').addBatch({
     'special characters': [
       'a{content : "  a > div { }  "}',
       'a{content:"  a > div { }  "}'
-    ]
+    ],
+    'with JSON': 'body::before{content:\'{ "current" : "small", "all" : ["small"], "position" : 0 }\'}'
   }),
   'zero values': cssContext({
     'with units': [
@@ -766,6 +767,7 @@ path")}',
     'should keep quotation if is a number': 'div[data-number=\'1\']{border-color:red}',
     'should keep quotation if starts with a number': 'div[data-type^=\'1something\']{border-color:red}',
     'should keep quotation if starts with a hyphen': 'div[data-type$=\'-something\']{border-color:red}',
+    'should keep quotation if key only (which is invalid)': 'div["data-type"]',
     'should strip quotation if is a word': [
       'a[data-href=\'object\']{border-color:red}',
       'a[data-href=object]{border-color:red}'