diff options
author | Keryn Knight <keryn@kerynknight.com> | 2022-01-25 09:53:03 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-01-29 13:50:34 +0100 |
commit | 55022f75c1e76e92206e023a127532d97cedd5b7 (patch) | |
tree | 18bf8e2360c74fe8ca5737a901379bd23f148dd7 /tests/utils_tests | |
parent | 67db54a5a7e0f1c2aa395e1db51214d09ae41f3f (diff) | |
download | django-55022f75c1e76e92206e023a127532d97cedd5b7.tar.gz |
Fixed #33465 -- Added empty __slots__ to SafeString and SafeData.
Despite inheriting from the str type, every SafeString instance gains
an empty __dict__ due to the normal, expected behaviour of type
subclassing in Python.
Adding __slots__ to SafeData is necessary, because otherwise inheriting
from that (as SafeString does) will give it a __dict__ and negate the
benefit added by modifying SafeString.
Diffstat (limited to 'tests/utils_tests')
-rw-r--r-- | tests/utils_tests/test_safestring.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/utils_tests/test_safestring.py b/tests/utils_tests/test_safestring.py index 2eeddb0571..80f31d42ac 100644 --- a/tests/utils_tests/test_safestring.py +++ b/tests/utils_tests/test_safestring.py @@ -2,7 +2,7 @@ from django.template import Context, Template from django.test import SimpleTestCase from django.utils import html from django.utils.functional import lazy, lazystr -from django.utils.safestring import SafeData, mark_safe +from django.utils.safestring import SafeData, SafeString, mark_safe class customescape(str): @@ -98,3 +98,15 @@ class SafeStringTest(SimpleTestCase): lazy_str = lazy(html_str, str)() self.assertEqual(mark_safe(lazy_str), html_str()) + + def test_default_additional_attrs(self): + s = SafeString('a&b') + msg = "object has no attribute 'dynamic_attr'" + with self.assertRaisesMessage(AttributeError, msg): + s.dynamic_attr = True + + def test_default_safe_data_additional_attrs(self): + s = SafeData() + msg = "object has no attribute 'dynamic_attr'" + with self.assertRaisesMessage(AttributeError, msg): + s.dynamic_attr = True |