Skip to content

Commit

Permalink
fix: ignore data-uri paths that contain variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
bingnz committed Jan 5, 2017
1 parent 8cd775c commit 2121aa0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/data-uri-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module dataUriVisitor {
argument = ruleNode.args[0];
}

if (!argument.value) {
if (!argument.value || /@/.test(argument.value)) {
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 @@ -359,6 +359,44 @@ describe('import-lister', () => {
});
});

describe('when passing in a file with a data-uri with an interpolated variable', () => {
const filePath = './test/list-imports-cases/file-with-data-uri-interpolated-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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@path: 'image.svg';
.a { background-image: data-uri('@{path}-123') }
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 2121aa0

Please sign in to comment.