Skip to content

Commit 7309984

Browse files
authored
Fix quoted strings templating (#3911)
Fixes: #3912
1 parent 3fbaa68 commit 7309984

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.github/workflows/tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
5252

5353
env:
54-
PYTEST_REQPASS: 454
54+
PYTEST_REQPASS: 455
5555
steps:
5656
- uses: actions/checkout@v3
5757
with:

src/molecule/test/unit/test_util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ def test_render_template():
179179
assert util.render_template(template, foo="foo", bar="bar") == "foo = bar"
180180

181181

182+
def test_render_template_quoted():
183+
template = """
184+
{{ 'url = "quoted_str"' }}
185+
""".strip()
186+
187+
assert util.render_template(template) == 'url = "quoted_str"'
188+
189+
182190
def test_write_file(temp_dir):
183191
dest_file = os.path.join(temp_dir.strpath, "test_util_write_file.tmp")
184192
contents = binascii.b2a_hex(os.urandom(15)).decode("utf-8")

src/molecule/util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ def os_walk(directory, pattern, excludes=[], followlinks=False):
175175

176176
def render_template(template, **kwargs):
177177
"""Render a jinaj2 template."""
178-
t = jinja2.Environment(autoescape=True)
178+
t = jinja2.Environment(
179+
autoescape=jinja2.select_autoescape(
180+
default_for_string=False,
181+
default=False,
182+
),
183+
)
179184
t = t.from_string(template)
180185

181186
return t.render(kwargs)

0 commit comments

Comments
 (0)