From ae9afff8d2c012ca760eb9c2adf41961cf6f6232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Sat, 12 Sep 2026 22:49:53 +0200 Subject: [PATCH] jinja : support dot property integer literals (#28817) --- common/jinja/runtime.cpp | 6 ++++++ tests/test-jinja.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/common/jinja/runtime.cpp b/common/jinja/runtime.cpp index 49354c7c9..252ab55de 100644 --- a/common/jinja/runtime.cpp +++ b/common/jinja/runtime.cpp @@ -842,6 +842,12 @@ value member_expression::execute_impl(context & ctx) { } else { property = this->property->execute(ctx); } + } else if (is_stmt(this->property)) { + // syntax: obj.index + property = mk_val(cast_stmt(this->property)->val); + if (property->as_int() < 0) { + throw std::runtime_error("Static member property cannot be negative"); + } } else { // syntax: obj.prop if (!is_stmt(this->property)) { diff --git a/tests/test-jinja.cpp b/tests/test-jinja.cpp index ab551d7b3..00de91ddf 100644 --- a/tests/test-jinja.cpp +++ b/tests/test-jinja.cpp @@ -398,6 +398,18 @@ static void test_expressions(testing & t) { "Bob" ); + test_template(t, "dot notation (integer property)", + "{{ {10: 'Bob'}.10 }}", + json::object(), + "Bob" + ); + + test_template(t, "dot notation (array index)", + "{{ user.10 }}", + {{"user", json::array({"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"})}}, + "k" + ); + test_template(t, "negative float (not dot notation)", "{{ -1.0 }}", json::object(),