Follow up to #86 removing line breaks and extra spaces on Windows.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 30 Mar 2013 11:09:24 +0000 (12:09 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 30 Mar 2013 11:17:22 +0000 (12:17 +0100)
lib/clean.js
test/unit-test.js

index 05b488d..3779351 100644 (file)
@@ -338,14 +338,14 @@ var CleanCSS = {
     replace(function moveCharset() {
       // get first charset in stylesheet
       var match = data.match(/@charset [^;]+;/);
-      var firstCharset = match ? match[0] : '';
-
-      // remove all charsets
-      data = data.replace(/@charset [^;]+;\n?/g, '');
-
-      // reattach first charset
-      if (firstCharset !== '')
-        data = firstCharset + (options.keepBreaks ? lineBreak : '') + data;
+      var firstCharset = match ? match[0] : null;
+      if (!firstCharset)
+        return;
+
+      // reattach first charset and remove all subsequent
+      data = firstCharset +
+        (options.keepBreaks ? lineBreak : '') +
+        data.replace(new RegExp('@charset [^;]+;(' + lineBreak + ')?', 'g'), '');
     });
 
     // trim spaces at beginning and end
index 13349b8..1b2d7f6 100644 (file)
@@ -159,6 +159,10 @@ vows.describe('clean-units').addBatch({
     'charset multiple charsets': [
       "@charset 'utf-8';\ndiv :before { display: block }\n@charset 'utf-8';\na { color: #f10 }",
       "@charset 'utf-8';" + lineBreak + "div :before{display:block}" + lineBreak + "a{color:#f10}"
+    ],
+    'charset with double line break': [
+      "@charset 'utf-8';" + lineBreak + lineBreak + "a{}",
+      "@charset 'utf-8';" + lineBreak + "a{}"
     ]
   }, { keepBreaks: true }),
   'selectors': cssContext({
@@ -693,6 +697,10 @@ title']",
     'multiple charsets': [
       "@charset 'utf-8';div :before { display: block }@charset 'utf-8';a { color: #f10 }",
       "@charset 'utf-8';div :before{display:block}a{color:#f10}"
+    ],
+    'charset and space after': [
+      "@charset 'utf-8';" + lineBreak + lineBreak + "a{}",
+      "@charset 'utf-8';a{}"
     ]
   }),
   'important': cssContext({