Commit 5c5eb5fe authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Fixed an inconsistency introduced in 547b1810.

mark_safe and mark_for_escaping should have been kept similar.

On Python 2 this change has no effect. On Python 3 it fixes the use case
shown in the regression test for mark_for_escaping, which used to raise
a TypeError. The regression test for mark_safe is just for completeness.
parent 89e2c60f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -144,4 +144,4 @@ def mark_for_escaping(s):
        return EscapeBytes(s)
    if isinstance(s, (six.text_type, Promise)):
        return EscapeText(s)
    return EscapeBytes(bytes(s))
    return EscapeString(str(s))
+18 −0
Original line number Diff line number Diff line
@@ -33,6 +33,15 @@ class SafeStringTest(TestCase):
        self.assertIsInstance(mark_safe(b), SafeData)
        self.assertRenderEqual('{{ s }}', 'a&b', s=mark_safe(s))

    def test_mark_safe_object_implementing_dunder_str(self):
        class Obj(object):
            def __str__(self):
                return '<obj>'

        s = mark_safe(Obj())

        self.assertRenderEqual('{{ s }}', '<obj>', s=s)

    def test_mark_for_escaping(self):
        s = mark_for_escaping('a&b')
        self.assertRenderEqual('{{ s }}', 'a&amp;b', s=s)
@@ -50,6 +59,15 @@ class SafeStringTest(TestCase):
        s = '<h1>interop</h1>'
        self.assertEqual(s, mark_safe(s).__html__())

    def test_mark_for_escaping_object_implementing_dunder_str(self):
        class Obj(object):
            def __str__(self):
                return '<obj>'

        s = mark_for_escaping(Obj())

        self.assertRenderEqual('{{ s }}', '&lt;obj&gt;', s=s)

    def test_add_lazy_safe_text_and_safe_text(self):
        s = html.escape(lazystr('a'))
        s += mark_safe('&b')