diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2022-11-16 21:37:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 14:37:05 -0600 |
commit | c5065264c2481f555bf3d12f46ac579c4961b25b (patch) | |
tree | 12306ccb5efe9b71ee40466131666872810151c2 /lib/ansible | |
parent | 59f3c0238b9b2f96e59bc95c5b792f8cf65b8e62 (diff) | |
download | ansible-c5065264c2481f555bf3d12f46ac579c4961b25b.tar.gz |
2.14: jinja2_native: preserve quotes in strings (#79119) (#79144)
* jinja2_native: preserve quotes in strings (#79119)
Fixes #79083
(cherry picked from commit d34b5786858f699ef36da6785464021889eaa672)
* Fix test for jinja2_native preserve quotes (#79131)
Fixes https://github.com/ansible/ansible/pull/79119#discussion_r993752129
(cherry picked from commit 3a6eca6670de77dd7d9f2713e5e1289b4a005683)
Diffstat (limited to 'lib/ansible')
-rw-r--r-- | lib/ansible/template/native_helpers.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/ansible/template/native_helpers.py b/lib/ansible/template/native_helpers.py index b6fc37b57d..343e10c709 100644 --- a/lib/ansible/template/native_helpers.py +++ b/lib/ansible/template/native_helpers.py @@ -128,7 +128,7 @@ def ansible_native_concat(nodes): out = ''.join([to_text(v) for v in nodes]) try: - return ast.literal_eval( + evaled = ast.literal_eval( # In Python 3.10+ ast.literal_eval removes leading spaces/tabs # from the given string. For backwards compatibility we need to # parse the string ourselves without removing leading spaces/tabs. @@ -136,3 +136,9 @@ def ansible_native_concat(nodes): ) except (ValueError, SyntaxError, MemoryError): return out + + if isinstance(evaled, string_types): + quote = out[0] + return f'{quote}{evaled}{quote}' + + return evaled |