Skip to content

Commit 062e966

Browse files
committedOct 22, 2023
Allow colon inside Twig.expression.type.key.brackets.
1 parent 00a6aff commit 062e966

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎src/twig.expression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ module.exports = function (Twig) {
913913
},
914914
{
915915
type: Twig.expression.type.key.brackets,
916-
regex: /^\[([^\]:]*)\]/,
916+
regex: /^\[([^\]]*)\]/,
917917
next: Twig.expression.set.operationsExtended.concat([
918918
Twig.expression.type.parameter.start
919919
]),

‎test/test.expressions.js

+5
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ describe('Twig.js Expressions ->', function () {
325325
const testTemplate = twig({data: '{% if a is defined and a %}true{% else %}false{% endif %}'});
326326
testTemplate.render({a: ['value']}).should.equal('true');
327327
});
328+
329+
it('should be able to access array elements with colons', function () {
330+
const testTemplate = twig({data: '{% for d in data["test:element"] %}{{ d.id }}{% endfor %}'});
331+
testTemplate.render({data: {'test:element':[{'id': 100}]}}).should.equal('100');
332+
});
328333
});
329334

330335
describe('Other Operators ->', function () {

0 commit comments

Comments
 (0)
Please sign in to comment.