Skip to content

Commit

Permalink
Respect autoescape=True from jinja_env passed to jinjax.Catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobGM committed Nov 29, 2023
1 parent 276d1fb commit 145e64a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/jinjax/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(

if jinja_env:
env.extensions.update(jinja_env.extensions)
env.autoescape = jinja_env.autoescape
globals.update(jinja_env.globals)
filters.update(jinja_env.filters)
tests.update(jinja_env.tests)
Expand Down
11 changes: 10 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import jinja2
import jinjax
import pytest


@pytest.fixture()
Expand All @@ -21,3 +22,11 @@ def catalog(folder):
catalog = jinjax.Catalog(auto_reload=False)
catalog.add_folder(folder)
return catalog


@pytest.fixture()
def autoescaped_catalog(folder):
jinja_env = jinja2.Environment(autoescape=True)
catalog = jinjax.Catalog(auto_reload=False, jinja_env=jinja_env)
catalog.add_folder(folder)
return catalog
5 changes: 2 additions & 3 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def test_auto_reload(catalog, folder):
""".strip() in html3


def test_autoescape_doesnot_escape_subcomponents(catalog, folder):
def test_autoescape_doesnot_escape_subcomponents(autoescaped_catalog, folder):
"""Issue https://github.com/jpsca/jinjax/issues/32"""
(folder / "Page.jinja").write_text("""
{#def message #}
Expand All @@ -481,8 +481,7 @@ def test_autoescape_doesnot_escape_subcomponents(catalog, folder):
<p>foo bar</p>
""")

catalog.jinja_env.autoescape = True
html = catalog.render("Page", message="<3")
html = autoescaped_catalog.render("Page", message="<3")
assert html == """
<html>
<p>lorem ipsum</p>
Expand Down

0 comments on commit 145e64a

Please sign in to comment.