Skip to content

Commit 6efa6de

Browse files
nuragicjoshwiens
authored andcommitted
fix: Support for empty tags in tag-attribute matching (#133)
Fix a bug introduced with #129.
1 parent 9e9bce2 commit 6efa6de

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ module.exports = function(content) {
3939
}
4040
var root = config.root;
4141
var links = attrParse(content, function(tag, attr) {
42-
var item = tag + ":" + attr;
4342
var res = attributes.find(function(a) {
44-
return item.indexOf(a) >= 0;
43+
if (a.charAt(0) === ':') {
44+
return attr === a.slice(1);
45+
} else {
46+
return (tag + ":" + attr) === a;
47+
}
4548
});
4649
return !!res;
4750
});

test/loaderTest.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ describe("loader", function() {
3636
'module.exports = "Text <custom-element custom-src=\\"" + require("./image1.png") + "\\"><custom-img custom-src=\\"" + require("./image2.png") + "\\"/></custom-element>";'
3737
);
3838
});
39+
it("should accept :attribute (empty tag) from query and not collide with similar attributes", function() {
40+
loader.call({
41+
query: "?attrs[]=:custom-src"
42+
}, 'Text <custom-element custom-src="image1.png" custom-src-other="other.png"><custom-img custom-src="image2.png"/></custom-element>').should.be.eql(
43+
'module.exports = "Text <custom-element custom-src=\\"" + require("./image1.png") + "\\" custom-src-other=\\"other.png\\"><custom-img custom-src=\\"" + require("./image2.png") + "\\"/></custom-element>";'
44+
);
45+
});
3946
it("should not make bad things with templates", function() {
4047
loader.call({}, '<h3>#{number} {customer}</h3>\n<p> {title} </p>').should.be.eql(
4148
'module.exports = "<h3>#{number} {customer}</h3>\\n<p> {title} </p>";'

0 commit comments

Comments
 (0)