diff options
| -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 21efb00b98..15c6a3052c 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 41ddca8560..11bc1a4f91 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -2754,8 +2754,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 @@ -2802,8 +2801,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") |
