mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Don't overwrite builtin jinja2 filters with tests (#37881)
* Don't overwrite builtin jinja2 filters with tests. Fixes #37856 * Fix tests and other callers of _get_filters
This commit is contained in:
parent
169209c32a
commit
1f824bd620
3 changed files with 12 additions and 4 deletions
|
@ -176,7 +176,7 @@ class Conditional:
|
|||
)
|
||||
try:
|
||||
e = templar.environment.overlay()
|
||||
e.filters.update(templar._get_filters())
|
||||
e.filters.update(templar._get_filters(e.filters))
|
||||
e.tests.update(templar._get_tests())
|
||||
|
||||
res = e._parse(conditional, None, None)
|
||||
|
|
|
@ -292,7 +292,7 @@ class Templar:
|
|||
))
|
||||
self._no_type_regex = re.compile(r'.*\|\s*(?:%s)\s*(?:%s)?$' % ('|'.join(C.STRING_TYPE_FILTERS), self.environment.variable_end_string))
|
||||
|
||||
def _get_filters(self):
|
||||
def _get_filters(self, builtin_filters):
|
||||
'''
|
||||
Returns filter plugins, after loading and caching them if need be
|
||||
'''
|
||||
|
@ -304,6 +304,9 @@ class Templar:
|
|||
|
||||
# TODO: Remove registering tests as filters in 2.9
|
||||
for name, func in self._get_tests().items():
|
||||
if name in builtin_filters:
|
||||
# If we have a custom test named the same as a builtin filter, don't register as a filter
|
||||
continue
|
||||
self._filters[name] = tests_as_filters_warning(name, func)
|
||||
|
||||
for fp in self._filter_loader.all():
|
||||
|
@ -678,7 +681,7 @@ class Templar:
|
|||
setattr(myenv, key, ast.literal_eval(val.strip()))
|
||||
|
||||
# Adds Ansible custom filters and tests
|
||||
myenv.filters.update(self._get_filters())
|
||||
myenv.filters.update(self._get_filters(myenv.filters))
|
||||
myenv.tests.update(self._get_tests())
|
||||
|
||||
if escape_backslashes:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue