Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 4ba55a6

Browse files
babolivierrichvdh
andauthored
Un-revert Jinja2 fix (#12313)
Co-authored-by: Richard van der Hoff <[email protected]>
1 parent 8cd760f commit 4ba55a6

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

changelog.d/12313.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix compatibility with the recently-released Jinja 3.1.

synapse/push/mailer.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import bleach
2020
import jinja2
21+
from markupsafe import Markup
2122

2223
from synapse.api.constants import EventTypes, Membership, RoomTypes
2324
from synapse.api.errors import StoreError
@@ -867,7 +868,7 @@ def _make_unsubscribe_link(
867868
)
868869

869870

870-
def safe_markup(raw_html: str) -> jinja2.Markup:
871+
def safe_markup(raw_html: str) -> Markup:
871872
"""
872873
Sanitise a raw HTML string to a set of allowed tags and attributes, and linkify any bare URLs.
873874
@@ -877,7 +878,7 @@ def safe_markup(raw_html: str) -> jinja2.Markup:
877878
Returns:
878879
A Markup object ready to safely use in a Jinja template.
879880
"""
880-
return jinja2.Markup(
881+
return Markup(
881882
bleach.linkify(
882883
bleach.clean(
883884
raw_html,
@@ -891,7 +892,7 @@ def safe_markup(raw_html: str) -> jinja2.Markup:
891892
)
892893

893894

894-
def safe_text(raw_text: str) -> jinja2.Markup:
895+
def safe_text(raw_text: str) -> Markup:
895896
"""
896897
Sanitise text (escape any HTML tags), and then linkify any bare URLs.
897898
@@ -901,7 +902,7 @@ def safe_text(raw_text: str) -> jinja2.Markup:
901902
Returns:
902903
A Markup object ready to safely use in a Jinja template.
903904
"""
904-
return jinja2.Markup(
905+
return Markup(
905906
bleach.linkify(bleach.clean(raw_text, tags=[], attributes=[], strip=False))
906907
)
907908

synapse/python_dependencies.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@
7474
# Note: 21.1.0 broke `/sync`, see #9936
7575
"attrs>=19.2.0,!=21.1.0",
7676
"netaddr>=0.7.18",
77-
# Jinja2 3.1.0 removes the deprecated jinja2.Markup class, which we rely on.
78-
"Jinja2<3.1.0",
77+
# Jinja 2.x is incompatible with MarkupSafe>=2.1. To ensure that admins do not
78+
# end up with a broken installation, with recent MarkupSafe but old Jinja, we
79+
# add a lower bound to the Jinja2 dependency.
80+
"Jinja2>=3.0",
7981
"bleach>=1.4.3",
8082
# We use `ParamSpec`, which was added in `typing-extensions` 3.10.0.0.
8183
"typing-extensions>=3.10.0",

0 commit comments

Comments
 (0)