Kaydet (Commit) ccfd1295 authored tarafından Claude Paroz's avatar Claude Paroz

Refs #27795 -- Prevented SafeText from losing safe status on str()

This will allow to replace force_text() by str() in several places (as one of
the features of force_text is to keep the safe status).
üst 274ca999
...@@ -54,6 +54,9 @@ class SafeText(str, SafeData): ...@@ -54,6 +54,9 @@ class SafeText(str, SafeData):
return SafeText(t) return SafeText(t)
return t return t
def __str__(self):
return self
SafeString = SafeText SafeString = SafeText
......
...@@ -24,6 +24,13 @@ class SafeStringTest(SimpleTestCase): ...@@ -24,6 +24,13 @@ class SafeStringTest(SimpleTestCase):
self.assertRenderEqual('{{ s }}', 'a&b', s=s) self.assertRenderEqual('{{ s }}', 'a&b', s=s)
self.assertRenderEqual('{{ s|force_escape }}', 'a&b', s=s) self.assertRenderEqual('{{ s|force_escape }}', 'a&b', s=s)
def test_mark_safe_str(self):
"""
Calling str() on a SafeText instance doesn't lose the safe status.
"""
s = mark_safe('a&b')
self.assertIsInstance(str(s), type(s))
def test_mark_safe_object_implementing_dunder_html(self): def test_mark_safe_object_implementing_dunder_html(self):
e = customescape('<a&b>') e = customescape('<a&b>')
s = mark_safe(e) s = mark_safe(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment