mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
keep string type filters as strings
now we don't try to convert types if using a filter that outputs a specifically formated string made list of filters configurable
This commit is contained in:
parent
a51b7d6b9a
commit
d82d65ee7b
2 changed files with 6 additions and 4 deletions
|
@ -261,6 +261,7 @@ GALAXY_SCMS = get_config(p, 'galaxy', 'scms', 'ANSIBLE_GALAXY
|
|||
|
||||
# characters included in auto-generated passwords
|
||||
DEFAULT_PASSWORD_CHARS = ascii_letters + digits + ".,:-_"
|
||||
STRING_TYPE_FILTERS = get_config(p, 'jinja2', 'dont_type_filters', 'ANSIBLE_STRING_TYPE_FILTERS', ['string', 'to_json', 'to_nice_json', 'to_yaml', 'ppretty', 'json'], islist=True )
|
||||
|
||||
# non-configurable things
|
||||
MODULE_REQUIRE_ARGS = ['command', 'shell', 'raw', 'script']
|
||||
|
|
|
@ -164,7 +164,8 @@ class Templar:
|
|||
self.block_end = self.environment.block_end_string
|
||||
self.variable_start = self.environment.variable_start_string
|
||||
self.variable_end = self.environment.variable_end_string
|
||||
self._clean_regex = re.compile(r'(?:%s[%s%s]|[%s%s]%s)' % (self.variable_start[0], self.variable_start[1], self.block_start[1], self.block_end[0], self.variable_end[0], self.variable_end[1]))
|
||||
self._clean_regex = re.compile(r'(?:%s|%s|%s|%s)' % (self.variable_start, self.block_start, self.block_end, self.variable_end))
|
||||
self._no_type_regex = re.compile(r'.*\|(?:%s)\s*(?:%s)?$' % ('|'.join(C.STRING_TYPE_FILTERS), self.variable_end))
|
||||
|
||||
def _get_filters(self):
|
||||
'''
|
||||
|
@ -278,8 +279,7 @@ class Templar:
|
|||
if fail_on_undefined is None:
|
||||
fail_on_undefined = self._fail_on_undefined_errors
|
||||
|
||||
# Don't template unsafe variables, instead drop them back down to
|
||||
# their constituent type.
|
||||
# Don't template unsafe variables, instead drop them back down to their constituent type.
|
||||
if hasattr(variable, '__UNSAFE__'):
|
||||
if isinstance(variable, text_type):
|
||||
return self._clean_data(text_type(variable))
|
||||
|
@ -294,6 +294,7 @@ class Templar:
|
|||
|
||||
if isinstance(variable, string_types):
|
||||
result = variable
|
||||
|
||||
if self._contains_vars(variable):
|
||||
|
||||
# Check to see if the string we are trying to render is just referencing a single
|
||||
|
@ -319,7 +320,7 @@ class Templar:
|
|||
result = self._cached_result[sha1_hash]
|
||||
else:
|
||||
result = self._do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, escape_backslashes=escape_backslashes, fail_on_undefined=fail_on_undefined, overrides=overrides)
|
||||
if convert_data:
|
||||
if convert_data and not self._no_type_regex.match(variable):
|
||||
# if this looks like a dictionary or list, convert it to such using the safe_eval method
|
||||
if (result.startswith("{") and not result.startswith(self.environment.variable_start_string)) or \
|
||||
result.startswith("[") or result in ("True", "False"):
|
||||
|
|
Loading…
Reference in a new issue