add support for alternative @import syntax
authorbanderson <bluej100@gmail.com>
Mon, 20 May 2013 17:04:58 +0000 (11:04 -0600)
committerbanderson <bluej100@gmail.com>
Mon, 20 May 2013 17:04:58 +0000 (11:04 -0600)
lib/clean.js
test/unit-test.js

index ee27502..1b89755 100644 (file)
@@ -365,7 +365,9 @@ var CleanCSS = {
 
     var inlinedFile = function() {
       var importedFile = data
-        .substring(data.indexOf('(', nextStart) + 1, nextEnd)
+        .substring(data.indexOf(' ', nextStart) + 1, nextEnd)
+        .replace(/^url\(/, '')
+        .replace(/\)$/, '')
         .replace(/['"]/g, '');
 
       if (/^(http|https):\/\//.test(importedFile))
@@ -392,17 +394,17 @@ var CleanCSS = {
     };
 
     for (; nextEnd < data.length; ) {
-      nextStart = data.indexOf('@import url(', cursor);
+      nextStart = data.indexOf('@import', cursor);
       if (nextStart == -1)
         break;
 
-      nextEnd = data.indexOf(')', nextStart);
+      nextEnd = data.indexOf(';', nextStart);
       if (nextEnd == -1)
         break;
 
       tempData.push(data.substring(cursor, nextStart));
       tempData.push(inlinedFile());
-      cursor = nextEnd + 2;
+      cursor = nextEnd + 1;
     }
 
     return tempData.length > 0 ?
index 67d1227..bda5be7 100644 (file)
@@ -785,6 +785,22 @@ title']",
       "@import url('test/data/partials/one.css');",
       ".one{color:red}"
     ],
+    'of a real file with double-quoted path': [
+      '@import url("test/data/partials/one.css");',
+      ".one{color:red}"
+    ],
+    'of a real file with bare path': [
+      "@import test/data/partials/one.css;",
+      ".one{color:red}"
+    ],
+    'of a real file with bare quoted path': [
+      "@import 'test/data/partials/one.css';",
+      ".one{color:red}"
+    ],
+    'of a real file with bare double-quoted path': [
+      '@import "test/data/partials/one.css";',
+      ".one{color:red}"
+    ],
     'of more files': [
       "@import url(test/data/partials/one.css);\n\na{}\n\n@import url(test/data/partials/extra/three.css);",
       ".one{color:red}a{}.three{color:#0f0}"