Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: stricter @import tolerance (#593)
* Added failed test for @import-normalize

* Fixed import handling not matching import like constructs.

* Made tolerant for null match on urls inside import

* Added request test case
  • Loading branch information
swernerx authored and joshwiens committed Aug 17, 2017
1 parent b92c941 commit 2e4ec09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/processCss.js
Expand Up @@ -42,12 +42,12 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
}

if(options.import) {
css.walkAtRules(/import/i, function(rule) {
css.walkAtRules(/^import$/i, function(rule) {
var values = Tokenizer.parseValues(rule.params);
var url = values.nodes[0].nodes[0];
if(url.type === "url") {
if(url && url.type === "url") {
url = url.url;
} else if(url.type === "string") {
} else if(url && url.type === "string") {
url = url.value;
} else throw rule.error("Unexpected format " + rule.params);
if (!url.replace(/\s/g, '').length) {
Expand Down
20 changes: 18 additions & 2 deletions test/importTest.js
@@ -1,6 +1,10 @@
/*globals describe */

var test = require("./helpers").test;
var assert = require('assert');

var helpers = require("./helpers");
var test = helpers.test;
var testError = helpers.testError;

describe("import", function() {
test("import", "@import url(test.css);\n.class { a: b c d; }", [
Expand Down Expand Up @@ -66,4 +70,16 @@ describe("import", function() {
test("import disabled", "@import url(test.css);\n.class { a: b c d; }", [
[1, "@import url(test.css);\n.class { a: b c d; }", ""]
], "?-import");
});
test("@import-normalize left untouched", "@import-normalize;", [
[1, "@import-normalize;", ""]
]);
testError("@import without url", "@import;", function(err) {
assert.equal(err.message, [
'Unexpected format (1:1)',
'',
'> 1 | @import;',
' | ^',
'',
].join('\n'))
})
})

0 comments on commit 2e4ec09

Please sign in to comment.