Skip to content

Commit

Permalink
fix: ignore data-uri calls with less variable as path.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Chandler authored and bingnz committed Jan 5, 2017
1 parent 779ca92 commit ab8adf3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/data-uri-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ module dataUriVisitor {
argument = ruleNode.args[0];
}

if (!argument.value) {
return ruleNode;
}

let importedFile = argument.value;
let entryPath = ruleNode.currentFileInfo.entryPath;

this._imports.push({ directory: ruleNode.currentFileInfo.entryPath, relativePath: importedFile });
this._imports.push({ directory: entryPath ? path.normalize(entryPath) : '', relativePath: importedFile });

return ruleNode;

Expand Down
38 changes: 38 additions & 0 deletions test/import-lister.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,44 @@ describe('import-lister', () => {
});
});

describe('when passing in a file with a data-uri with a variable', () => {
const filePath = './test/list-imports-cases/file-with-data-uri-variable/file.less';
it('should return no imports', () => {
return readFile(new File({ path: filePath }))
.then(f => importLister.listImports(f))
.then(importList => expect(importList).to.be.empty);
});

it('should not use the path resolver', () => {
const resolvedPath = 'some/path/image.svg';
let resolverFunction = {
resolve: function() {
return Promise.resolve(resolvedPath);
}
};

let pathResolver = {
PathResolver: function()
{
return resolverFunction;
}
};

let fsStub = new FakeFs();
fsStub.file(resolvedPath, { mtime: new Date() });

sinon.spy(resolverFunction, 'resolve');
importLister = new (getImportLister({ pathResolver: pathResolver, fs: fsStub }));

return readFile(new File({ path: filePath }))
.then(f => importLister.listImports(f))
.then(importList => {
expect(importList).to.be.empty;
expect(resolverFunction.resolve).not.to.have.been.called;
});
});
});

describe('when passing in a file as a buffered stream', () => {
const filePath = './test/list-imports-cases/file-with-recursive-imports/file.less';
it('should return the imports', () => {
Expand Down
2 changes: 2 additions & 0 deletions test/list-imports-cases/file-with-data-uri-variable/file.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@path: 'image.svg';
.a { background-image: data-uri(@path) }
3 changes: 3 additions & 0 deletions test/list-imports-cases/file-with-data-uri-variable/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab8adf3

Please sign in to comment.