Comment 8 for bug 2024325

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Looking at the patch:

Description: make compatible with markupsafe 2.1.0
Origin: backport, https://trac.edgewall.org/changeset/17575 and https://trac.edgewall.org/changeset/17543
Bug-Ubuntu: https://launchpad.net/bugs/2024325
Last-Update: 2024-01-29
---

--- trac-1.5.3+dfsg.orig/trac/util/html.py
+++ trac-1.5.3+dfsg/trac/util/html.py
@@ -25,6 +25,10 @@ from html import entities
 from html.parser import HTMLParser

 from markupsafe import Markup, escape as escape_quotes
+try:
+ from markupsafe import soft_str as soft_unicode
+except ImportError:
+ from markupsafe import soft_unicode

 try:
     from babel.support import LazyProxy
--- trac-1.5.3+dfsg.orig/trac/util/presentation.py
+++ trac-1.5.3+dfsg/trac/util/presentation.py
@@ -23,11 +23,11 @@ import re

 from jinja2 import Markup, Undefined, contextfilter, evalcontextfilter
 from jinja2.filters import make_attrgetter
-from jinja2.utils import soft_unicode

 from trac.core import TracError
 from .datefmt import to_utimestamp, utc
-from .html import Fragment, classes, html_attribute, styles, tag
+from .html import (Fragment, Markup, classes, html_attribute, soft_unicode,
+ styles, tag)
 from .text import javascript_quote

 __all__ = ['captioned_button', 'classes', 'first_last', 'group', 'istext',

a) In presentation.py, you are leaving the "from jinja2 import Markup" bit, and again, later down, importing it again via "from .html import Markup", which is a change you added.

That comes from https://trac.edgewall.org/changeset/17543, but note that that diff also *removed* the Markup import from jinja2:
-from jinja2 import Markup, Undefined, contextfilter, evalcontextfilter
+from jinja2 import Undefined, contextfilter, evalcontextfilter

Could you please review these changes, and the import changes overall in the patch?

b) If I understood this correctly, this is the big import change: soft_unicode is no longer imported from jinja2.utils, but now comes from markupsafe *either* as soft_unicode, or renamed from soft_str. What's the story here? What guarantees do we have that these modules are accurate replacements? Did jinja2.utils remove soft_unicode in some version, and if yes, in which?