summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
authorShai Berger <shai@platonix.com>2024-02-19 13:56:37 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-03-04 08:22:00 +0100
commitf6ad8c7676f85dfde5a279b6b1469251421289e2 (patch)
treefab12a57619f5627f70093da3bfb84708984c6d6 /tests/utils_tests
parentf5ed4306bbfd2e5543dd02cf5a22326a29253cdf (diff)
Refs CVE-2024-27351 -- Forwardported release notes and tests.
Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/utils_tests')
-rw-r--r--tests/utils_tests/test_text.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py
index b38d8238c5..ab2cfb3f7c 100644
--- a/tests/utils_tests/test_text.py
+++ b/tests/utils_tests/test_text.py
@@ -292,6 +292,33 @@ class TestUtilsText(SimpleTestCase):
truncator = text.Truncator("foo</p>")
self.assertEqual("foo</p>", truncator.words(3, html=True))
+ # Only open brackets.
+ truncator = text.Truncator("<" * 60_000)
+ self.assertEqual(truncator.words(1, html=True), "&lt;…")
+
+ # Tags with special chars in attrs.
+ truncator = text.Truncator(
+ """<i style="margin: 5%; font: *;">Hello, my dear lady!</i>"""
+ )
+ self.assertEqual(
+ """<i style="margin: 5%; font: *;">Hello, my dear…</i>""",
+ truncator.words(3, html=True),
+ )
+
+ # Tags with special non-latin chars in attrs.
+ truncator = text.Truncator("""<p data-x="א">Hello, my dear lady!</p>""")
+ self.assertEqual(
+ """<p data-x="א">Hello, my dear…</p>""",
+ truncator.words(3, html=True),
+ )
+
+ # Misplaced brackets.
+ truncator = text.Truncator("hello >< world")
+ self.assertEqual(truncator.words(1, html=True), "hello…")
+ self.assertEqual(truncator.words(2, html=True), "hello &gt;…")
+ self.assertEqual(truncator.words(3, html=True), "hello &gt;&lt;…")
+ self.assertEqual(truncator.words(4, html=True), "hello &gt;&lt; world")
+
@patch("django.utils.text.Truncator.MAX_LENGTH_HTML", 10_000)
def test_truncate_words_html_size_limit(self):
max_len = text.Truncator.MAX_LENGTH_HTML