Skip to content

Commit

Permalink
fix: Support for empty tags in tag-attribute matching (#133)
Browse files Browse the repository at this point in the history
Fix a bug introduced with #129.
  • Loading branch information
nuragic authored and joshwiens committed Aug 8, 2017
1 parent 9e9bce2 commit 6efa6de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ module.exports = function(content) {
}
var root = config.root;
var links = attrParse(content, function(tag, attr) {
var item = tag + ":" + attr;
var res = attributes.find(function(a) {
return item.indexOf(a) >= 0;
if (a.charAt(0) === ':') {
return attr === a.slice(1);
} else {
return (tag + ":" + attr) === a;
}
});
return !!res;
});
Expand Down
7 changes: 7 additions & 0 deletions test/loaderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ describe("loader", function() {
'module.exports = "Text <custom-element custom-src=\\"" + require("./image1.png") + "\\"><custom-img custom-src=\\"" + require("./image2.png") + "\\"/></custom-element>";'
);
});
it("should accept :attribute (empty tag) from query and not collide with similar attributes", function() {
loader.call({
query: "?attrs[]=:custom-src"
}, 'Text <custom-element custom-src="image1.png" custom-src-other="other.png"><custom-img custom-src="image2.png"/></custom-element>').should.be.eql(
'module.exports = "Text <custom-element custom-src=\\"" + require("./image1.png") + "\\" custom-src-other=\\"other.png\\"><custom-img custom-src=\\"" + require("./image2.png") + "\\"/></custom-element>";'
);
});
it("should not make bad things with templates", function() {
loader.call({}, '<h3>#{number} {customer}</h3>\n<p> {title} </p>').should.be.eql(
'module.exports = "<h3>#{number} {customer}</h3>\\n<p> {title} </p>";'
Expand Down

0 comments on commit 6efa6de

Please sign in to comment.