mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -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,
|
||||
'contains': (l, r) => {
|
||||
return typeof l !== 'undefined'
|
||||
? typeof l.indexOf === 'function'
|
||||
? l.indexOf(r) > -1
|
||||
: false
|
||||
: false;
|
||||
'contains': (l, r) => {
|
||||
if (!l) return false;
|
||||
if (typeof l.indexOf !== 'function') return false;
|
||||
return l.indexOf(r) > -1;
|
||||
},
|
||||
'and': (l, r) => l && r,
|
||||
'or': (l, r) => l || r
|
||||
|
||||
+3
-1
@@ -14,7 +14,8 @@ describe('expression', function() {
|
||||
one: 1,
|
||||
two: 2,
|
||||
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('1 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 6', scope)).to.equal(false);
|
||||
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
|
||||
|
||||
Reference in New Issue
Block a user