From ea095e3d1fdf8b82c6fc12e0baf736715b8b99ee Mon Sep 17 00:00:00 2001 From: nuragic Date: Mon, 17 Jul 2017 08:21:42 +0200 Subject: [PATCH] fix(index, loaderTest) support for empty tags in tag-attribute matching Fix a bug introduced with #129. --- index.js | 7 +++++-- test/loaderTest.js | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ba1049d2..88527455 100644 --- a/index.js +++ b/index.js @@ -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; }); diff --git a/test/loaderTest.js b/test/loaderTest.js index 2546f443..dedb3d32 100644 --- a/test/loaderTest.js +++ b/test/loaderTest.js @@ -36,6 +36,13 @@ describe("loader", function() { 'module.exports = "Text ";' ); }); + it("should accept :attribute (empty tag) from query and not collide with similar attributes", function() { + loader.call({ + query: "?attrs[]=:custom-src" + }, 'Text ').should.be.eql( + 'module.exports = "Text ";' + ); + }); it("should not make bad things with templates", function() { loader.call({}, '

#{number} {customer}

\n

{title}

').should.be.eql( 'module.exports = "

#{number} {customer}

\\n

{title}

";'