Fixes issue with tokenizer removing first selector after an unknown @ rule.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 29 Jul 2014 20:42:20 +0000 (21:42 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 2 Aug 2014 10:40:19 +0000 (11:40 +0100)
See discussion in #325.

History.md
lib/selectors/tokenizer.js
test/unit-test.js

index c12d3a1..73d0d90 100644 (file)
@@ -1,3 +1,8 @@
+[2.2.12 / 2014-xx-xx](https://github.com/GoalSmashers/clean-css/compare/v2.2.11...v2.2.12)
+==================
+
+* Fixed issue with tokenizer removing first selector after an unknown @ rule.
+
 [2.2.11 / 2014-07-28](https://github.com/GoalSmashers/clean-css/compare/v2.2.10...v2.2.11)
 ==================
 
index d674946..ab57d32 100644 (file)
@@ -70,8 +70,9 @@ module.exports = function Tokenizer(data, minifyContext) {
       var oldMode;
 
       if (what == 'special') {
-        var fragment = chunk.substring(nextSpecial, context.cursor + '@font-face'.length + 1);
-        var isSingle = fragment.indexOf('@import') === 0 || fragment.indexOf('@charset') === 0;
+        var firstOpenBraceAt = chunk.indexOf('{', nextSpecial);
+        var firstSemicolonAt = chunk.indexOf(';', nextSpecial);
+        var isSingle = firstSemicolonAt > -1 && (firstOpenBraceAt == -1 || firstSemicolonAt < firstOpenBraceAt);
         if (isSingle) {
           nextEnd = chunk.indexOf(';', nextSpecial + 1);
           tokenized.push(chunk.substring(context.cursor, nextEnd + 1));
index c8dd594..9cc3f53 100644 (file)
@@ -2049,7 +2049,8 @@ title']{display:block}",
     'merging color with backgrounds': [
       'p{background:red;background-image:url(1.png),url(2.png)}',
       'p{background:url(1.png),url(2.png) red}'
-    ]
+    ],
+    'unknown @ rule': '@unknown "test";h1{color:red}'
   }),
   'viewport units': cssContext({
     'shorthand margin with viewport width not changed': 'div{margin:5vw}'