diff --git a/src/operators.js b/src/operators.js index ba93de411..a93ce7980 100644 --- a/src/operators.js +++ b/src/operators.js @@ -1,10 +1,10 @@ var operators = { '==': (l, r) => l == r, '!=': (l, r) => l != r, - '>': (l, r) => l > r, - '<': (l, r) => l < r, - '>=': (l, r) => l >= r, - '<=': (l, r) => l <= r, + '>': (l, r) => l !== null && r !== null && l > r, + '<': (l, r) => l !== null && r !== null && l < r, + '>=': (l, r) => l !== null && r !== null && l >= r, + '<=': (l, r) => l !== null && r !== null && l <= r, 'contains': (l, r) => { if (!l) return false; if (typeof l.indexOf !== 'function') return false; diff --git a/test/tags/if.js b/test/tags/if.js index 14af05ede..9fca81803 100644 --- a/test/tags/if.js +++ b/test/tags/if.js @@ -52,4 +52,53 @@ describe('tags/if', function() { return expect(liquid.parseAndRender(src, ctx)) .to.eventually.equal('a'); }); + + it('should return else when comparison on null 1', function() { + var src = "{% if null < 10 %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + + it('should return else when comparison on null 2', function() { + var src = "{% if null <= 10 %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + + it('should return else when comparison on null 3', function() { + var src = "{% if null >= 10 %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + + it('should return else when comparison on null 4', function() { + var src = "{% if null > 10 %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + + it('should return else when comparison on null 5', function() { + var src = "{% if 10 < null %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + + it('should return else when comparison on null 6', function() { + var src = "{% if 10 <= null %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + + it('should return else when comparison on null 7', function() { + var src = "{% if 10 >= null %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + + it('should return else when comparison on null 8', function() { + var src = "{% if 10 > null %}yes{% else %}no{% endif %}"; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('no'); + }); + });