Skip to content

Commit

Permalink
Merge pull request TryGhost#4781 from ErisDS/has-tag-fix
Browse files Browse the repository at this point in the history
Fix has helper tag matching
  • Loading branch information
jaswilli committed Jan 11, 2015
2 parents 64d2907 + 3f34162 commit be462d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/server/helpers/has.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions core/test/unit/server_helpers/has_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit be462d8

Please sign in to comment.