diff --git a/src/twig.expression.operator.js b/src/twig.expression.operator.js index 027382e1..1ef23ab5 100644 --- a/src/twig.expression.operator.js +++ b/src/twig.expression.operator.js @@ -17,6 +17,11 @@ module.exports = function (Twig) { return null; } + if (b && Array.isArray(b)) { + // Array + return JSON.stringify(b).includes(JSON.stringify(a)); + } + if (b.indexOf !== undefined) { // String return (a === b || a !== '') && b.includes(a); diff --git a/test/test.expressions.js b/test/test.expressions.js index 3563bd80..c0d61a71 100644 --- a/test/test.expressions.js +++ b/test/test.expressions.js @@ -381,6 +381,12 @@ describe('Twig.js Expressions ->', function () { testTemplate = twig({data: '{{ "d" in ["a", "b", "c"] }}'}); testTemplate.render().should.equal(false.toString()); + + testTemplate = twig({data: '{{ ["a", "b"] in [["a", "b"], ["c", "d"]] }}'}); + testTemplate.render().should.equal(true.toString()); + + testTemplate = twig({data: '{{ ["a", "c"] in [["a", "b"], ["c", "d"]] }}'}); + testTemplate.render().should.equal(false.toString()); }); it('should support not in/containment functionality for arrays', function () { @@ -391,6 +397,12 @@ describe('Twig.js Expressions ->', function () { testTemplate = twig({data: '{{ "d" not in ["a", "b", "c"] }}'}); testTemplate.render().should.equal(true.toString()); + + testTemplate = twig({data: '{{ ["a", "b"] not in [["a", "b"], ["c", "d"]] }}'}); + testTemplate.render().should.equal(false.toString()); + + testTemplate = twig({data: '{{ ["a", "c"] not in [["a", "b"], ["c", "d"]] }}'}); + testTemplate.render().should.equal(true.toString()); }); it('should support in/containment functionality for strings', function () {