jinja: correct member access rule (#18905)

This commit is contained in:
Xuan-Son Nguyen 2026-01-18 00:48:55 +01:00 committed by GitHub
parent d1b4757ded
commit f55b033ae6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 2 deletions

View file

@ -1063,6 +1063,18 @@ static void test_object_methods(testing & t) {
{{"obj", {{"items", json::array({1, 2, 3})}}}},
"{\"items\": [1, 2, 3]}"
);
test_template(t, "object attribute and key access",
"{{ obj.keys()|join(',') }} vs {{ obj['keys'] }} vs {{ obj.test }}",
{{"obj", {{"keys", "value"}, {"test", "attr_value"}}}},
"keys,test vs value vs attr_value"
);
test_template(t, "env should not have object methods",
"{{ keys is undefined }} {{ obj.keys is defined }}",
{{"obj", {{"a", "b"}}}},
"True True"
);
}
static void test_template(testing & t, const std::string & name, const std::string & tmpl, const json & vars, const std::string & expect) {