diff --git a/src/twig.expression.js b/src/twig.expression.js index 0e2ea9f2..e58322c6 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 6620479a..3563bd80 100644 --- a/test/test.expressions.js +++ b/test/test.expressions.js @@ -332,6 +332,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 () {