Fixes #86 - broken charset replacing when preceeded by text content.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 30 Mar 2013 09:04:41 +0000 (10:04 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 30 Mar 2013 09:04:41 +0000 (10:04 +0100)
History.md
lib/clean.js
test/data/charset-mixed-with-fonts-min.css [new file with mode: 0644]
test/data/charset-mixed-with-fonts.css [new file with mode: 0644]

index a2e187b..d909401 100644 (file)
@@ -9,6 +9,7 @@
 * Fixed issue [#80](https://github.com/GoalSmashers/clean-css/issues/80) - quotation in multi line strings.
 * Fixed issue [#92](https://github.com/GoalSmashers/clean-css/issues/92) - uppercase hex to short versions.
 * Fixed issue [#88](https://github.com/GoalSmashers/clean-css/issues/88) - removes space in '! important'.
+* Fixed issue [#86](https://github.com/GoalSmashers/clean-css/issues/86) - broken @charset replacing.
 
 0.10.2 / 2013-03-19
 ==================
index 6e1561a..60293b6 100644 (file)
@@ -295,20 +295,6 @@ var CleanCSS = {
     // restore rect(...) zeros syntax for 4 zeros
     replace(/rect\(\s?0(\s|,)0[ ,]0[ ,]0\s?\)/g, 'rect(0$10$10$10)');
 
-    // move first charset to the beginning
-    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;
-    });
-
     if (options.removeEmpty) {
       // empty elements
       replace(/[^\{\}]+\{\}/g, '');
@@ -348,6 +334,20 @@ var CleanCSS = {
       }
     });
 
+    // move first charset to the beginning
+    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;
+    });
+
     // trim spaces at beginning and end
     return data.trim();
   },
diff --git a/test/data/charset-mixed-with-fonts-min.css b/test/data/charset-mixed-with-fonts-min.css
new file mode 100644 (file)
index 0000000..c410169
--- /dev/null
@@ -0,0 +1,3 @@
+@charset "UTF-8";
+@font-face{font-family:ProximaNova-Regular;src:url(/assets/thirdParty/css/1415F2_1.eot);src:url(/assets/thirdParty/css/1415F2_1IE.eot) format('embedded-opentype'),url(/assets/thirdParty/css/1415F2_1.woff) format('woff'),url(/assets/thirdParty/css/1415F2_1.ttf) format('truetype'),url(/assets/thirdParty/css/1415F2_1.svg) format('svg')}
+blockquote small:before{content:'\2014 \00A0'}
diff --git a/test/data/charset-mixed-with-fonts.css b/test/data/charset-mixed-with-fonts.css
new file mode 100644 (file)
index 0000000..2378967
--- /dev/null
@@ -0,0 +1,14 @@
+@font-face {
+  font-family: 'ProximaNova-Regular';
+  src: url('/assets/thirdParty/css/1415F2_1.eot');
+  src: url('/assets/thirdParty/css/1415F2_1IE.eot') format('embedded-opentype'),
+    url('/assets/thirdParty/css/1415F2_1.woff') format('woff'),
+    url('/assets/thirdParty/css/1415F2_1.ttf') format('truetype'),
+    url('/assets/thirdParty/css/1415F2_1.svg') format('svg');
+}
+
+@charset "UTF-8";
+/* (c) 2012 Instagram, Inc, */
+blockquote small:before {
+  content: '\2014 \00A0';
+}