From 7ec845708bf05393261aee85409334c10250adca Mon Sep 17 00:00:00 2001 From: banderson Date: Mon, 20 May 2013 11:04:58 -0600 Subject: [PATCH] add support for alternative @import syntax --- lib/clean.js | 10 ++++++---- test/unit-test.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/clean.js b/lib/clean.js index ee27502a..1b897557 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -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 ? diff --git a/test/unit-test.js b/test/unit-test.js index 67d12277..bda5be71 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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}" -- 2.34.1