mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Merge pull request #4781 from ErisDS/has-tag-fix
Fix has helper tag matching
This commit is contained in:
commit
be462d8d94
2 changed files with 27 additions and 1 deletions
|
@ -25,7 +25,7 @@ has = function (options) {
|
||||||
return p || (_.findIndex(tags, function (item) {
|
return p || (_.findIndex(tags, function (item) {
|
||||||
// Escape regex special characters
|
// Escape regex special characters
|
||||||
item = item.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&');
|
item = item.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&');
|
||||||
item = new RegExp(item, 'i');
|
item = new RegExp('^' + item + '$', 'i');
|
||||||
return item.test(c);
|
return item.test(c);
|
||||||
}) !== -1);
|
}) !== -1);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
|
@ -44,6 +44,32 @@ describe('{{#has}} helper', function () {
|
||||||
inverse.called.should.be.false;
|
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 () {
|
it('should handle tag list that validates false', function () {
|
||||||
var fn = sinon.spy(),
|
var fn = sinon.spy(),
|
||||||
inverse = sinon.spy();
|
inverse = sinon.spy();
|
||||||
|
|
Loading…
Add table
Reference in a new issue