Skip to content

fix: attr matching for empty tags in tag:attribute patterns #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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