|
| 1 | +From 01e50061072389bc315db7c55e5489eb5370a5f7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: David Lord <davidism@gmail.com> |
| 3 | +Date: Wed, 5 Mar 2025 10:08:48 -0800 |
| 4 | +Subject: [PATCH] attr filter uses env.getattr |
| 5 | + |
| 6 | +--- |
| 7 | + deps/v8/third_party/jinja2/filters.py | 30 +++++++++++---------------- |
| 8 | + 1 file changed, 12 insertions(+), 18 deletions(-) |
| 9 | + |
| 10 | +diff --git a/deps/v8/third_party/jinja2/filters.py b/deps/v8/third_party/jinja2/filters.py |
| 11 | +index 1daf42bc..e71cb5ca 100644 |
| 12 | +--- a/deps/v8/third_party/jinja2/filters.py |
| 13 | ++++ b/deps/v8/third_party/jinja2/filters.py |
| 14 | +@@ -5,6 +5,7 @@ import random |
| 15 | + import re |
| 16 | + import warnings |
| 17 | + from collections import namedtuple |
| 18 | ++from inspect import getattr_static |
| 19 | + from itertools import chain |
| 20 | + from itertools import groupby |
| 21 | + |
| 22 | +@@ -1072,28 +1073,21 @@ def do_reverse(value): |
| 23 | + @environmentfilter |
| 24 | + def do_attr(environment, obj, name): |
| 25 | + """Get an attribute of an object. ``foo|attr("bar")`` works like |
| 26 | +- ``foo.bar`` just that always an attribute is returned and items are not |
| 27 | +- looked up. |
| 28 | ++ ``foo.bar``, but returns undefined instead of falling back to ``foo["bar"]`` |
| 29 | ++ if the attribute doesn't exist. |
| 30 | + |
| 31 | + See :ref:`Notes on subscriptions <notes-on-subscriptions>` for more details. |
| 32 | + """ |
| 33 | + try: |
| 34 | +- name = str(name) |
| 35 | +- except UnicodeError: |
| 36 | +- pass |
| 37 | +- else: |
| 38 | +- try: |
| 39 | +- value = getattr(obj, name) |
| 40 | +- except AttributeError: |
| 41 | +- pass |
| 42 | +- else: |
| 43 | +- if environment.sandboxed and not environment.is_safe_attribute( |
| 44 | +- obj, name, value |
| 45 | +- ): |
| 46 | +- return environment.unsafe_undefined(obj, name) |
| 47 | +- return value |
| 48 | +- return environment.undefined(obj=obj, name=name) |
| 49 | +- |
| 50 | ++ # This avoids executing properties/descriptors, but misses __getattr__ |
| 51 | ++ # and __getattribute__ dynamic attrs. |
| 52 | ++ getattr_static(obj, name) |
| 53 | ++ except AttributeError: |
| 54 | ++ # This finds dynamic attrs, and we know it's not a descriptor at this point. |
| 55 | ++ if not hasattr(obj, name): |
| 56 | ++ return environment.undefined(obj=obj, name=name) |
| 57 | ++ |
| 58 | ++ return environment.getattr(obj, name) |
| 59 | + |
| 60 | + @contextfilter |
| 61 | + def do_map(*args, **kwargs): |
| 62 | +-- |
| 63 | +2.40.4 |
| 64 | + |
0 commit comments