diff options
| author | Natalia <124304+nessita@users.noreply.github.com> | 2026-02-25 10:37:38 -0300 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2026-02-25 13:09:57 -0300 |
| commit | d112203b19946659335db6462043f8652e6700a1 (patch) | |
| tree | 6b0187c8a63eca54c22ea169650adf358510119d | |
| parent | 090f1da56e663e9f840e307e73b5cf011cb7b061 (diff) | |
[6.0.x] Fixed #36944 -- Removed MAX_LENGTH_HTML and related 5M chars limit references from HTML truncation docs.
Backport of bbc6818bc12f14c1764a7eb68556018195f56b59 from main.
| -rw-r--r-- | django/utils/text.py | 6 | ||||
| -rw-r--r-- | docs/ref/templates/builtins.txt | 6 | ||||
| -rw-r--r-- | tests/utils_tests/test_text.py | 36 |
3 files changed, 2 insertions, 46 deletions
diff --git a/django/utils/text.py b/django/utils/text.py index 29f5c8f2e8..0fc32720ad 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -185,14 +185,8 @@ class TruncateWordsHTMLParser(TruncateHTMLParser): class Truncator(SimpleLazyObject): """ An object used to truncate text, either by characters or words. - - When truncating HTML text (either chars or words), input will be limited to - at most `MAX_LENGTH_HTML` characters. """ - # 5 million characters are approximately 4000 text pages or 3 web pages. - MAX_LENGTH_HTML = 5_000_000 - def __init__(self, text): super().__init__(lambda: str(text)) diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 9eee51beba..94ec4a6be5 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -2860,8 +2860,7 @@ Newlines in the HTML content will be preserved. .. admonition:: Size of input string Processing large, potentially malformed HTML strings can be - resource-intensive and impact service performance. ``truncatechars_html`` - limits input to the first five million characters. + resource-intensive and impact service performance. .. templatefilter:: truncatewords @@ -2908,8 +2907,7 @@ Newlines in the HTML content will be preserved. .. admonition:: Size of input string Processing large, potentially malformed HTML strings can be - resource-intensive and impact service performance. ``truncatewords_html`` - limits input to the first five million characters. + resource-intensive and impact service performance. .. templatefilter:: unordered_list diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index 11c01874cb..50e205a254 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -1,6 +1,5 @@ import json import sys -from unittest.mock import patch from django.core.exceptions import SuspiciousFileOperation from django.test import SimpleTestCase @@ -136,23 +135,6 @@ class TestUtilsText(SimpleTestCase): truncator = text.Truncator("foo</p>") self.assertEqual("foo</p>", truncator.chars(5, html=True)) - @patch("django.utils.text.Truncator.MAX_LENGTH_HTML", 10_000) - def test_truncate_chars_html_size_limit(self): - max_len = text.Truncator.MAX_LENGTH_HTML - bigger_len = text.Truncator.MAX_LENGTH_HTML + 1 - valid_html = "<p>Joel is a slug</p>" # 14 chars - perf_test_values = [ - ("</a" + "\t" * (max_len - 6) + "//>", "</a>"), - ("</p" + "\t" * bigger_len + "//>", "</p>"), - ("&" * bigger_len, ""), - ("_X<<<<<<<<<<<>", "_X<<<<<<<…"), - (valid_html * bigger_len, "<p>Joel is a…</p>"), # 10 chars - ] - for value, expected in perf_test_values: - with self.subTest(value=value): - truncator = text.Truncator(value) - self.assertEqual(expected, truncator.chars(10, html=True)) - def test_truncate_chars_html_with_newline_inside_tag(self): truncator = text.Truncator( '<p>The quick <a href="xyz.html"\n id="mylink">brown fox</a> jumped over ' @@ -329,24 +311,6 @@ class TestUtilsText(SimpleTestCase): self.assertEqual(truncator.words(3, html=True), "hello ><…") self.assertEqual(truncator.words(4, 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 - bigger_len = text.Truncator.MAX_LENGTH_HTML + 1 - valid_html = "<p>Joel is a slug</p>" # 4 words - perf_test_values = [ - ("</a" + "\t" * (max_len - 6) + "//>", "</a>"), - ("</p" + "\t" * bigger_len + "//>", "</p>"), - ("&" * max_len, ""), - ("&" * bigger_len, ""), - ("_X<<<<<<<<<<<>", "_X<<<<<<<<<<<>"), - (valid_html * bigger_len, valid_html * 12 + "<p>Joel is…</p>"), # 50 words - ] - for value, expected in perf_test_values: - with self.subTest(value=value): - truncator = text.Truncator(value) - self.assertEqual(expected, truncator.words(50, html=True)) - def test_wrap(self): digits = "1234 67 9" self.assertEqual(text.wrap(digits, 100), "1234 67 9") |
