From 3f34162fd99d02d435146e3e919b4f5c5db16288 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 9 Jan 2015 21:52:23 +0000 Subject: [PATCH] Fix has helper tag matching fixes #4780 --- core/server/helpers/has.js | 2 +- core/test/unit/server_helpers/has_spec.js | 26 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/server/helpers/has.js b/core/server/helpers/has.js index ae4296a8e4..6e8752816d 100644 --- a/core/server/helpers/has.js +++ b/core/server/helpers/has.js @@ -25,7 +25,7 @@ has = function (options) { return p || (_.findIndex(tags, function (item) { // Escape regex special characters item = item.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&'); - item = new RegExp(item, 'i'); + item = new RegExp('^' + item + '$', 'i'); return item.test(c); }) !== -1); }, false); diff --git a/core/test/unit/server_helpers/has_spec.js b/core/test/unit/server_helpers/has_spec.js index 64a17fd9ed..86fa5a12c6 100644 --- a/core/test/unit/server_helpers/has_spec.js +++ b/core/test/unit/server_helpers/has_spec.js @@ -44,6 +44,32 @@ describe('{{#has}} helper', function () { inverse.called.should.be.false; }); + it('should match exact tags, not superstrings', function () { + var fn = sinon.spy(), + inverse = sinon.spy(); + + helpers.has.call( + {tags: [{name: 'magical'}]}, + {hash: {tag: 'magic'}, fn: fn, inverse: inverse} + ); + + fn.called.should.be.false; + inverse.called.should.be.true; + }); + + it('should match exact tags, not substrings', function () { + var fn = sinon.spy(), + inverse = sinon.spy(); + + helpers.has.call( + {tags: [{name: 'magic'}]}, + {hash: {tag: 'magical'}, fn: fn, inverse: inverse} + ); + + fn.called.should.be.false; + inverse.called.should.be.true; + }); + it('should handle tag list that validates false', function () { var fn = sinon.spy(), inverse = sinon.spy();