diff --git a/src/jinjax/catalog.py b/src/jinjax/catalog.py index 88836e1..ef6cfbb 100644 --- a/src/jinjax/catalog.py +++ b/src/jinjax/catalog.py @@ -104,6 +104,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) diff --git a/tests/conftest.py b/tests/conftest.py index 537a068..c1f9b2a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ -import pytest +import jinja2 import jinjax +import pytest @pytest.fixture() @@ -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 diff --git a/tests/test_render.py b/tests/test_render.py index 6aa7e1a..2aa478a 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -470,7 +470,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 #} @@ -485,8 +485,7 @@ def test_autoescape_doesnot_escape_subcomponents(catalog, folder):

foo bar

""") - catalog.jinja_env.autoescape = True - html = catalog.render("Page", message="<3") + html = autoescaped_catalog.render("Page", message="<3") assert html == """

lorem ipsum