Skip to content

Commit 2e4ec09

Browse files
swernerxjoshwiens
authored andcommittedAug 17, 2017
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
1 parent b92c941 commit 2e4ec09

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed
 

‎lib/processCss.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
4242
}
4343

4444
if(options.import) {
45-
css.walkAtRules(/import/i, function(rule) {
45+
css.walkAtRules(/^import$/i, function(rule) {
4646
var values = Tokenizer.parseValues(rule.params);
4747
var url = values.nodes[0].nodes[0];
48-
if(url.type === "url") {
48+
if(url && url.type === "url") {
4949
url = url.url;
50-
} else if(url.type === "string") {
50+
} else if(url && url.type === "string") {
5151
url = url.value;
5252
} else throw rule.error("Unexpected format " + rule.params);
5353
if (!url.replace(/\s/g, '').length) {

‎test/importTest.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/*globals describe */
22

3-
var test = require("./helpers").test;
3+
var assert = require('assert');
4+
5+
var helpers = require("./helpers");
6+
var test = helpers.test;
7+
var testError = helpers.testError;
48

59
describe("import", function() {
610
test("import", "@import url(test.css);\n.class { a: b c d; }", [
@@ -66,4 +70,16 @@ describe("import", function() {
6670
test("import disabled", "@import url(test.css);\n.class { a: b c d; }", [
6771
[1, "@import url(test.css);\n.class { a: b c d; }", ""]
6872
], "?-import");
69-
});
73+
test("@import-normalize left untouched", "@import-normalize;", [
74+
[1, "@import-normalize;", ""]
75+
]);
76+
testError("@import without url", "@import;", function(err) {
77+
assert.equal(err.message, [
78+
'Unexpected format (1:1)',
79+
'',
80+
'> 1 | @import;',
81+
' | ^',
82+
'',
83+
].join('\n'))
84+
})
85+
})

0 commit comments

Comments
 (0)
Please sign in to comment.