diff options
| author | Shai Berger <shai@platonix.com> | 2024-02-19 13:56:37 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-03-04 08:36:56 +0100 |
| commit | 3c9a2771cc80821e041b16eb36c1c37af5349d4a (patch) | |
| tree | 61c59939f8632cd4a62f6991236bee09e5d172c7 /tests/utils_tests/test_text.py | |
| parent | 79739511397367c56d20393b93c5edd35f5cca53 (diff) | |
[4.2.x] Fixed CVE-2024-27351 -- Prevented potential ReDoS in Truncator.words().
Thanks Seokchan Yoon for the report.
Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/utils_tests/test_text.py')
| -rw-r--r-- | tests/utils_tests/test_text.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index 7d20445b1e..d1890e7b6d 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -183,6 +183,32 @@ class TestUtilsText(SimpleTestCase): truncator = text.Truncator("<p>I <3 python, what about you?</p>") self.assertEqual("<p>I <3 python,…</p>", truncator.words(3, html=True)) + # Only open brackets. + test = "<" * 60_000 + truncator = text.Truncator(test) + self.assertEqual(truncator.words(1, html=True), test) + + # 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 >< 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 |
