You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> from jinja2.nativetypes import NativeEnvironment
>>> e = NativeEnvironment()
>>> t = e.from_string("'{{ foo }}', '{{ bar }}', '{{ baz }}'")
>>> t.render(foo='foobar', bar='barbaz', baz='bazfoo')
'foobar, barbaz, bazfoo'
Your Environment
Python version: 2.7.5
Jinja version: 2.10, 2.10.1, current master
Trying to find an explanation of the on the above. Tested this in an interpreter to narrow it down to just Jinja2, and nothing else that may be calling it, such as Ansible with jinja2_native set to True.
When not using jinja2_native, we get the expected behavior above that the three substitutions occur with single quotes around each value. When jinja2_native is set to true (in the NativeEnvironment as shown above), the inner single quotes in the string are disregarded, and a single string is returned with the three substitutions.
This also occurs even with additional characters between the single quotes:
>>> e = NativeEnvironment()
>>> t = e.from_string("--foo='{{ foo }}' --bar='{{ bar }}'")
>>> t.render(foo='foobar', bar='barbaz')
u"--foo='foobar --bar=barbaz'"
Any help would be appreciated.
The text was updated successfully, but these errors were encountered:
To add a little note on why this (more or less) happens: the template "--foo='{{ foo }}' --bar='{{ bar }}'" is broken down to the following nodes:
--foo='
{{ foo }}
' --bar='
{{ bar }}
'"
The problem happens when native_concat processes 3. ' --bar=', literal_eval there sees a string, strips the quotes and returns just --bar= which is correct, just not in this context :)
Expected Behavior
Actual Behavior
Your Environment
Trying to find an explanation of the on the above. Tested this in an interpreter to narrow it down to just Jinja2, and nothing else that may be calling it, such as Ansible with jinja2_native set to True.
When not using jinja2_native, we get the expected behavior above that the three substitutions occur with single quotes around each value. When jinja2_native is set to true (in the NativeEnvironment as shown above), the inner single quotes in the string are disregarded, and a single string is returned with the three substitutions.
This also occurs even with additional characters between the single quotes:
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: