From 062e966d8502d99fc975097eb075f9e4678bea25 Mon Sep 17 00:00:00 2001 From: Antoine Veldhoven Date: Sun, 22 Oct 2023 18:37:36 +0200 Subject: [PATCH] Allow colon inside Twig.expression.type.key.brackets. --- src/twig.expression.js | 2 +- test/test.expressions.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/twig.expression.js b/src/twig.expression.js index 80a8b4dc..69b33bba 100644 --- a/src/twig.expression.js +++ b/src/twig.expression.js @@ -913,7 +913,7 @@ module.exports = function (Twig) { }, { type: Twig.expression.type.key.brackets, - regex: /^\[([^\]:]*)\]/, + regex: /^\[([^\]]*)\]/, next: Twig.expression.set.operationsExtended.concat([ Twig.expression.type.parameter.start ]), diff --git a/test/test.expressions.js b/test/test.expressions.js index fb414283..b6577664 100644 --- a/test/test.expressions.js +++ b/test/test.expressions.js @@ -325,6 +325,11 @@ describe('Twig.js Expressions ->', function () { const testTemplate = twig({data: '{% if a is defined and a %}true{% else %}false{% endif %}'}); testTemplate.render({a: ['value']}).should.equal('true'); }); + + it('should be able to access array elements with colons', function () { + const testTemplate = twig({data: '{% for d in data["test:element"] %}{{ d.id }}{% endfor %}'}); + testTemplate.render({data: {'test:element':[{'id': 100}]}}).should.equal('100'); + }); }); describe('Other Operators ->', function () {