mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-29 07:05:13 -07:00
fix: contains return false when left side equals null
This commit is contained in:
+4
-6
@@ -5,12 +5,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,
|
||||||
'contains': (l, r) => {
|
'contains': (l, r) => {
|
||||||
return typeof l !== 'undefined'
|
if (!l) return false;
|
||||||
? typeof l.indexOf === 'function'
|
if (typeof l.indexOf !== 'function') return false;
|
||||||
? l.indexOf(r) > -1
|
return l.indexOf(r) > -1;
|
||||||
: false
|
|
||||||
: false;
|
|
||||||
},
|
},
|
||||||
'and': (l, r) => l && r,
|
'and': (l, r) => l && r,
|
||||||
'or': (l, r) => l || r
|
'or': (l, r) => l || r
|
||||||
|
|||||||
+3
-1
@@ -14,7 +14,8 @@ describe('expression', function() {
|
|||||||
one: 1,
|
one: 1,
|
||||||
two: 2,
|
two: 2,
|
||||||
x: 'XXX',
|
x: 'XXX',
|
||||||
y: undefined
|
y: undefined,
|
||||||
|
z: null
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ describe('expression', function() {
|
|||||||
expect(evalExp('x contains "X"', scope)).to.equal(true);
|
expect(evalExp('x contains "X"', scope)).to.equal(true);
|
||||||
expect(evalExp('1 contains "x"', scope)).to.equal(false);
|
expect(evalExp('1 contains "x"', scope)).to.equal(false);
|
||||||
expect(evalExp('y contains "x"', scope)).to.equal(false);
|
expect(evalExp('y contains "x"', scope)).to.equal(false);
|
||||||
|
expect(evalExp('z contains "x"', scope)).to.equal(false);
|
||||||
expect(evalExp('(1..5) contains 3', scope)).to.equal(true);
|
expect(evalExp('(1..5) contains 3', scope)).to.equal(true);
|
||||||
expect(evalExp('(1..5) contains 6', scope)).to.equal(false);
|
expect(evalExp('(1..5) contains 6', scope)).to.equal(false);
|
||||||
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
|
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user