mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Un-revert Jinja2 fix (#12313)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
8cd760fca8
commit
4ba55a620f
1
changelog.d/12313.misc
Normal file
1
changelog.d/12313.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix compatibility with the recently-released Jinja 3.1.
|
@ -18,6 +18,7 @@ from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, TypeVar
|
|||||||
|
|
||||||
import bleach
|
import bleach
|
||||||
import jinja2
|
import jinja2
|
||||||
|
from markupsafe import Markup
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes, Membership, RoomTypes
|
from synapse.api.constants import EventTypes, Membership, RoomTypes
|
||||||
from synapse.api.errors import StoreError
|
from synapse.api.errors import StoreError
|
||||||
@ -867,7 +868,7 @@ class Mailer:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def safe_markup(raw_html: str) -> jinja2.Markup:
|
def safe_markup(raw_html: str) -> Markup:
|
||||||
"""
|
"""
|
||||||
Sanitise a raw HTML string to a set of allowed tags and attributes, and linkify any bare URLs.
|
Sanitise a raw HTML string to a set of allowed tags and attributes, and linkify any bare URLs.
|
||||||
|
|
||||||
@ -877,7 +878,7 @@ def safe_markup(raw_html: str) -> jinja2.Markup:
|
|||||||
Returns:
|
Returns:
|
||||||
A Markup object ready to safely use in a Jinja template.
|
A Markup object ready to safely use in a Jinja template.
|
||||||
"""
|
"""
|
||||||
return jinja2.Markup(
|
return Markup(
|
||||||
bleach.linkify(
|
bleach.linkify(
|
||||||
bleach.clean(
|
bleach.clean(
|
||||||
raw_html,
|
raw_html,
|
||||||
@ -891,7 +892,7 @@ def safe_markup(raw_html: str) -> jinja2.Markup:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def safe_text(raw_text: str) -> jinja2.Markup:
|
def safe_text(raw_text: str) -> Markup:
|
||||||
"""
|
"""
|
||||||
Sanitise text (escape any HTML tags), and then linkify any bare URLs.
|
Sanitise text (escape any HTML tags), and then linkify any bare URLs.
|
||||||
|
|
||||||
@ -901,7 +902,7 @@ def safe_text(raw_text: str) -> jinja2.Markup:
|
|||||||
Returns:
|
Returns:
|
||||||
A Markup object ready to safely use in a Jinja template.
|
A Markup object ready to safely use in a Jinja template.
|
||||||
"""
|
"""
|
||||||
return jinja2.Markup(
|
return Markup(
|
||||||
bleach.linkify(bleach.clean(raw_text, tags=[], attributes=[], strip=False))
|
bleach.linkify(bleach.clean(raw_text, tags=[], attributes=[], strip=False))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -74,8 +74,10 @@ REQUIREMENTS = [
|
|||||||
# Note: 21.1.0 broke `/sync`, see #9936
|
# Note: 21.1.0 broke `/sync`, see #9936
|
||||||
"attrs>=19.2.0,!=21.1.0",
|
"attrs>=19.2.0,!=21.1.0",
|
||||||
"netaddr>=0.7.18",
|
"netaddr>=0.7.18",
|
||||||
# Jinja2 3.1.0 removes the deprecated jinja2.Markup class, which we rely on.
|
# Jinja 2.x is incompatible with MarkupSafe>=2.1. To ensure that admins do not
|
||||||
"Jinja2<3.1.0",
|
# end up with a broken installation, with recent MarkupSafe but old Jinja, we
|
||||||
|
# add a lower bound to the Jinja2 dependency.
|
||||||
|
"Jinja2>=3.0",
|
||||||
"bleach>=1.4.3",
|
"bleach>=1.4.3",
|
||||||
# We use `ParamSpec`, which was added in `typing-extensions` 3.10.0.0.
|
# We use `ParamSpec`, which was added in `typing-extensions` 3.10.0.0.
|
||||||
"typing-extensions>=3.10.0",
|
"typing-extensions>=3.10.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user