Skip to content

Commit

Permalink
Allow colon inside Twig.expression.type.key.brackets.
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineveldhoven committed Oct 22, 2023
1 parent 00a6aff commit 062e966
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/twig.expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
]),
Expand Down
5 changes: 5 additions & 0 deletions test/test.expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 062e966

Please sign in to comment.