Fixes #159 - escaped quotes inside content property.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 2 Nov 2013 09:07:04 +0000 (10:07 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 2 Nov 2013 09:07:04 +0000 (10:07 +0100)
History.md
lib/text/free.js
test/data/issue-159-snippet-min.css [new file with mode: 0644]
test/data/issue-159-snippet.css [new file with mode: 0644]

index 069b41a..e1a3696 100644 (file)
@@ -6,6 +6,7 @@
 * Adds simplified and much faster empty elements removal.
 * Adds missing `@import` processing to our benchmark (run via `npm run bench`).
 * Fixed issue [#157](https://github.com/GoalSmashers/clean-css/issues/157) - gets rid of `removeEmpty` option.
+* Fixed issue [#159](https://github.com/GoalSmashers/clean-css/issues/159) - escaped quotes inside content.
 
 1.1.7 / 2013-10-28
 ==================
index dab22b1..c66c403 100644 (file)
@@ -3,6 +3,22 @@ var EscapeStore = require('./escape-store');
 module.exports = function Free() {
   var texts = new EscapeStore('CSSFREETEXT');
 
+  var findNonEscapedEnd = function(data, matched, start) {
+    var end = start;
+    while (true) {
+      end = data.indexOf(matched, end);
+
+      if (end > -1 && data[end - 1] == '\\') {
+        end += 1;
+        continue;
+      } else {
+        break;
+      }
+    }
+
+    return end;
+  };
+
   return {
     // Strip content tags by replacing them by the __CSSFREETEXT__
     // marker for further restoring. It's done via string scanning
@@ -37,8 +53,8 @@ module.exports = function Free() {
         if (nextStart == -1)
           break;
 
-        nextEnd = data.indexOf(matchedParenthesis, nextStart + 1);
-        if (nextStart == -1 || nextEnd == -1)
+        nextEnd = findNonEscapedEnd(data, matchedParenthesis, nextStart + 1);
+        if (nextEnd == -1)
           break;
 
         var text = data.substring(nextStart, nextEnd + 1);
diff --git a/test/data/issue-159-snippet-min.css b/test/data/issue-159-snippet-min.css
new file mode 100644 (file)
index 0000000..3c24142
--- /dev/null
@@ -0,0 +1,7 @@
+.zocial.acrobat:before{content:"\00E3";color:#FB0000}
+.zocial.amazon:before{content:"a"}
+.zocial.android:before{content:"&"}
+.zocial.angellist:before{content:"\00D6"}
+.zocial.aol:before{content:"\""}
+.zocial.appnet:before{content:"\00E1"}
+.zocial.appstore:before{content:"A"}
diff --git a/test/data/issue-159-snippet.css b/test/data/issue-159-snippet.css
new file mode 100644 (file)
index 0000000..7c64f05
--- /dev/null
@@ -0,0 +1,7 @@
+.zocial.acrobat:before {content: "\00E3"; color: #FB0000;}
+.zocial.amazon:before {content: "a";}
+.zocial.android:before {content: "&";}
+.zocial.angellist:before {content: "\00D6";}
+.zocial.aol:before {content: "\"";}
+.zocial.appnet:before {content: "\00E1";}
+.zocial.appstore:before {content: "A";}