Repository: django/django

Issue:
# Fixed #36944 -- Removed MAX_LENGTH_HTML and related 5M chars limit references from HTML truncation docs.

#### Trac ticket number
<!-- Replace XXXXX with the corresponding Trac ticket number. -->
<!-- Or delete the line and write "N/A" if this is a trivial PR. -->

ticket-36944

#### Branch description
Following up some security reports, we noticed the docs around HTML length limit enforcement was outdated. This work cleans that up.

#### AI Assistance Disclosure (REQUIRED)
<!-- Please select exactly ONE of the following: -->
- [X] **No AI tools were used** in preparing this PR.
- [ ] **If AI tools were used**, I have disclosed which ones, and fully reviewed and verified their output.

#### Checklist
- [X] This PR follows the [contribution guidelines](https://docs.djangoproject.com/en/stable/internals/contributing/writing-code/submitting-patches/).
- [X] This PR **does not** disclose a security vulnerability (see [vulnerability reporting](https://docs.djangoproject.com/en/stable/internals/security/)).
- [X] This PR targets the `main` branch. <!-- Backports will be evaluated and done by mergers, when necessary. -->
- [X] The commit message is written in past tense, mentions the ticket number, and ends with a period.
- [X] I have checked the "Has patch" ticket flag in the Trac system.
- [ ] I have added or updated relevant tests.
- [X] I have added or updated relevant docs, including release notes if applicable.
- [ ] I have attached screenshots in both light and dark modes for any UI changes.


Implementation patch:
diff --git a/django/utils/text.py b/django/utils/text.py
index ef4baa935bf2..cfe6ceca9e4b 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -185,14 +185,8 @@ def process(self, data):
 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))
 


Test patch:
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py
index 11c01874cb5d..50e205a25449 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 @@ def test_truncate_chars_html(self):
         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&lt;&lt;&lt;&lt;&lt;&lt;&lt;…"),
-            (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 @@ def test_truncate_html_words(self):
         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
-        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&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;"),
-            (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")