Skip to content
Myr

Add .svg to select_jinja_autoescape (#4840)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

As SVG files are a type of XML file and are similar in nearly all aspects to XML, .svg should also be autoescaped.

authored by Jonah Lawrence · committed by GitHub · parent 3dc6db9 · Browse files · 3 files+8 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+8 added−2 removed

  • other:+8 added−2 removed

3 files+8 added−2 removed

modified:docs/templating.rst+1 added-1 removed
16 unmodified lines
1718Unless customized, Jinja2 is configured by Flask as follows:1920- autoescaping is enabled for all templates ending in ``.html``,21 ``.htm``, ``.xml`` as well as ``.xhtml`` when using21 ``.htm``, ``.xml``, ``.xhtml``, as well as ``.svg`` when using22 :func:`~flask.templating.render_template`.23- autoescaping is enabled for all strings when using24 :func:`~flask.templating.render_template_string`.25- a template has the ability to opt in/out autoescaping with the
204 unmodified lines
modified:src/flask/app.py+4 added-1 removed
959 unmodified lines
960 def select_jinja_autoescape(self, filename: str) -> bool:961 """Returns ``True`` if autoescaping should be active for the given962 template name. If no template name is given, returns `True`.963964 .. versionchanged:: 2.2965 Autoescaping is now enabled by default for ``.svg`` files.966967 .. versionadded:: 0.5968 """969 if filename is None:970 return True968 return filename.endswith((".html", ".htm", ".xml", ".xhtml"))971 return filename.endswith((".html", ".htm", ".xml", ".xhtml", ".svg"))972973 def update_template_context(self, context: dict) -> None:974 """Update the template context with some commonly used variables.975 This injects request, session, config and g into the template
1576 unmodified lines
modified:CHANGES.rst+3 added
7 unmodified lines
8-------------910Unreleased1112- Autoescaping is now enabled by default for ``.svg`` files. Inside13 templates this behavior can be changed with the ``autoescape`` tag.14 :issue:`4831`1516Version 2.2.217-------------18
1404 unmodified lines