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

Un-revert Jinja2 fix #12313

Merged
merged 6 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12313.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly import `Markup` from `MarkupSafe` instead of `Jinja2`.
richvdh marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 5 additions & 4 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import bleach
import jinja2
from markupsafe import Markup

from synapse.api.constants import EventTypes, Membership, RoomTypes
from synapse.api.errors import StoreError
Expand Down Expand Up @@ -867,7 +868,7 @@ def _make_unsubscribe_link(
)


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.

Expand All @@ -877,7 +878,7 @@ def safe_markup(raw_html: str) -> jinja2.Markup:
Returns:
A Markup object ready to safely use in a Jinja template.
"""
return jinja2.Markup(
return Markup(
bleach.linkify(
bleach.clean(
raw_html,
Expand All @@ -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.

Expand All @@ -901,7 +902,7 @@ def safe_text(raw_text: str) -> jinja2.Markup:
Returns:
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))
)

Expand Down
3 changes: 1 addition & 2 deletions synapse/python_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@
# Note: 21.1.0 broke `/sync`, see #9936
"attrs>=19.2.0,!=21.1.0",
"netaddr>=0.7.18",
# Jinja2 3.1.0 removes the deprecated jinja2.Markup class, which we rely on.
"Jinja2<3.1.0",
"Jinja2~=3.0",
richvdh marked this conversation as resolved.
Show resolved Hide resolved
babolivier marked this conversation as resolved.
Show resolved Hide resolved
"bleach>=1.4.3",
# We use `ParamSpec`, which was added in `typing-extensions` 3.10.0.0.
"typing-extensions>=3.10.0",
Expand Down