summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authorGabriel Nick Pivovarov <113646197+gnpivo@users.noreply.github.com>2024-12-05 16:24:47 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-12-06 10:44:10 +0100
commit55855bc6d0d2a270eb34952c578ee352389367ad (patch)
tree638393b4f02d923470cbcf79e61161201aa1b57d /tests/template_tests
parentded485464214a3f69b64402b7d82221279f80008 (diff)
Fixed #35493 -- Allowed template self-inclusion with relative paths.
Co-authored-by: Brock <bsmick97@gmail.com>
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/syntax_tests/test_include.py46
-rw-r--r--tests/template_tests/templates/recursive_relative_include.html7
2 files changed, 44 insertions, 9 deletions
diff --git a/tests/template_tests/syntax_tests/test_include.py b/tests/template_tests/syntax_tests/test_include.py
index 3ee99b3798..be0deee926 100644
--- a/tests/template_tests/syntax_tests/test_include.py
+++ b/tests/template_tests/syntax_tests/test_include.py
@@ -330,15 +330,43 @@ class IncludeTests(SimpleTestCase):
],
}
]
- engine = Engine(app_dirs=True)
- t = engine.get_template("recursive_include.html")
- self.assertEqual(
- "Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
- t.render(Context({"comments": comments}))
- .replace(" ", "")
- .replace("\n", " ")
- .strip(),
- )
+ with self.subTest(template="recursive_include.html"):
+ engine = Engine(app_dirs=True)
+ t = engine.get_template("recursive_include.html")
+ self.assertEqual(
+ "Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
+ t.render(Context({"comments": comments}))
+ .replace(" ", "")
+ .replace("\n", " ")
+ .strip(),
+ )
+ with self.subTest(template="recursive_relative_include.html"):
+ engine = Engine(app_dirs=True)
+ t = engine.get_template("recursive_relative_include.html")
+ self.assertEqual(
+ "Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
+ t.render(Context({"comments": comments}))
+ .replace(" ", "")
+ .replace("\n", " ")
+ .strip(),
+ )
+ with self.subTest(template="tmpl"):
+ engine = Engine()
+ template = """
+ Recursion!
+ {% for c in comments %}
+ {{ c.comment }}
+ {% if c.children %}{% include tmpl with comments=c.children %}{% endif %}
+ {% endfor %}
+ """
+ outer_tmpl = engine.from_string("{% include tmpl %}")
+ output = outer_tmpl.render(
+ Context({"tmpl": engine.from_string(template), "comments": comments})
+ )
+ self.assertEqual(
+ "Recursion! A1 Recursion! B1 B2 B3 Recursion! C1",
+ output.replace(" ", "").replace("\n", " ").strip(),
+ )
def test_include_cache(self):
"""
diff --git a/tests/template_tests/templates/recursive_relative_include.html b/tests/template_tests/templates/recursive_relative_include.html
new file mode 100644
index 0000000000..ae49cc0a43
--- /dev/null
+++ b/tests/template_tests/templates/recursive_relative_include.html
@@ -0,0 +1,7 @@
+Recursion!
+{% for comment in comments %}
+ {{ comment.comment }}
+ {% if comment.children %}
+ {% include "./recursive_relative_include.html" with comments=comment.children %}
+ {% endif %}
+{% endfor %}