MCPcopy
hub / github.com/encode/starlette / test_templates_autoescape

Function test_templates_autoescape

tests/test_templates.py:37–46  ·  view source on GitHub ↗
(tmp_path: Path)

Source from the content-addressed store, hash-verified

35
36
37def test_templates_autoescape(tmp_path: Path) -> None:
38 path = tmp_path / "index.html"
39 path.write_text("Hello, {{ name }}")
40
41 templates = Jinja2Templates(directory=tmp_path)
42 template = templates.get_template("index.html")
43 assert (
44 template.render(name="<script>alert('XSS')</script>")
45 == "Hello, &lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt;"
46 )
47
48
49def test_calls_context_processors(tmp_path: Path, test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

get_templateMethod · 0.95
Jinja2TemplatesClass · 0.90
renderMethod · 0.45

Tested by

no test coverage detected