diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a8c9b0..cc8376c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,15 @@ instead of repeating its id (#270), and each result carries its confidence as the `confidence` property (#271). A flow reaching its sink inside a project function points at that sink as a related location, which the result's message links to (#271). +- Django templates are also read as each page is put together (#273): a variable a + child's `{% block %}` prints inside its parent's `", "{% if c %}", "{% endif %}"] + + +def test_a_template_including_itself_is_established_only_if_its_unfoldings_are(tmp_path: Path) -> None: + """For generated templates including themselves, established means every unfolding + of the recursion, written out as templates including each other down to one that + includes nothing, is established too.""" + + from coretrace_python.taint.templates import escaped_templates + + rng = random.Random(273) + root = tmp_path / "project" + directory = root / "app" / "templates" + directory.mkdir(parents=True) + count, depth = 3_000, 4 + for index in range(count): + before = "".join(rng.choice(TEMPLATE_PIECES) for _ in range(rng.randint(0, 3))) + after = "".join(rng.choice(TEMPLATE_PIECES) for _ in range(rng.randint(0, 3))) + # Half of them include themselves under a condition, the others without one: a + # tag after the include would end a comment its markup leaves open. + opening, closing = ("{% if more %}", "{% endif %}") if index % 2 else ("", "") + written = { + f"t{index}.html": f"{{% include 't{index}.html' %}}", + f"t{index}-0.html": "", + **{f"t{index}-{level}.html": f"{{% include 't{index}-{level - 1}.html' %}}" for level in range(1, depth)}, + } + for name, included in written.items(): + (directory / name).write_text(f"{before}{opening}{included}{closing}{after}", encoding="utf-8") + established = escaped_templates(root) + recursive = [index for index in range(count) if f"t{index}.html" in established] + assert recursive + for index in recursive: + assert all(f"t{index}-{level}.html" in established for level in range(depth)), index