}
function byImport(data, context, callback) {
+ var nextImport = 0;
+ var nextImportUpperCase = 0;
var nextStart = 0;
- var nextStartUpperCase = 0;
var nextEnd = 0;
var cursor = 0;
var tempData = [];
var nextSingleQuote = 0;
var nextDoubleQuote = 0;
+ var untilNextQuote;
var withQuote;
var SINGLE_QUOTE = '\'';
var DOUBLE_QUOTE = '"';
for (; nextEnd < data.length;) {
- nextStart = data.indexOf(IMPORT_URL_PREFIX, nextEnd);
- nextStartUpperCase = data.indexOf(UPPERCASE_IMPORT_URL_PREFIX, nextEnd);
- if (nextStart == -1 && nextStartUpperCase == -1)
+ nextImport = data.indexOf(IMPORT_URL_PREFIX, nextEnd);
+ nextImportUpperCase = data.indexOf(UPPERCASE_IMPORT_URL_PREFIX, nextEnd);
+ if (nextImport == -1 && nextImportUpperCase == -1)
break;
- if (nextStart > -1 && nextStartUpperCase > -1 && nextStartUpperCase < nextStart)
- nextStart = nextStartUpperCase;
+ if (nextImport > -1 && nextImportUpperCase > -1 && nextImportUpperCase < nextImport)
+ nextImport = nextImportUpperCase;
- nextSingleQuote = data.indexOf(SINGLE_QUOTE, nextStart);
- nextDoubleQuote = data.indexOf(DOUBLE_QUOTE, nextStart);
+ nextSingleQuote = data.indexOf(SINGLE_QUOTE, nextImport);
+ nextDoubleQuote = data.indexOf(DOUBLE_QUOTE, nextImport);
if (nextSingleQuote > -1 && nextDoubleQuote > -1 && nextSingleQuote < nextDoubleQuote) {
nextStart = nextSingleQuote;
} else if (nextDoubleQuote > -1) {
nextStart = nextDoubleQuote;
withQuote = DOUBLE_QUOTE;
+ } else {
+ break;
}
tempData.push(data.substring(cursor, nextStart));
-
nextEnd = data.indexOf(withQuote, nextStart + 1);
- if (nextEnd == -1) {
+
+ untilNextQuote = data.substring(nextImport, nextEnd);
+ if (nextEnd == -1 || /^@import\s+(url\(|__ESCAPED)/i.test(untilNextQuote)) {
cursor = nextStart;
break;
}
],
'no empty body': '@import url(//fonts.googleapis.com/css?family=Domine:700);body{color:red}body h1{font-family:Domine}'
}, { processImport: false, advanced: false }),
+ '@import with no url': cssContext({
+ 'matching too much': [
+ '@import url(test.css);@font-face{font-family:"icomoon"}',
+ '@import url(test.css);@font-face{font-family:icomoon}'
+ ]
+ }, { processImport: false, root: process.cwd(), relativeTo: process.cwd() }),
'duplicate selectors with disabled advanced processing': cssContext({
'of a duplicate selector': [
'a,a{color:red}',