diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 37e87aa1022c..9c22b61b4ff2 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -962,7 +962,7 @@ def test_parsing_errors(self): "('Unexpected end tag `div` (Line 1, Column 6)', (1, 6))" ) with self.assertRaisesMessage(AssertionError, error_msg): - self.assertHTMLEqual("< div>", "
") + self.assertHTMLEqual("< div>", "
") with self.assertRaises(HTMLParseError): parse_html("

") diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py index 284f33aedcfb..f1a29977a743 100644 --- a/tests/utils_tests/test_html.py +++ b/tests/utils_tests/test_html.py @@ -1,4 +1,5 @@ import os +import sys from datetime import datetime from django.core.exceptions import SuspiciousOperation @@ -115,6 +116,21 @@ def test_linebreaks(self): self.check_output(linebreaks, lazystr(value), output) def test_strip_tags(self): + # Python fixed a quadratic-time issue in HTMLParser in 3.13.6, 3.12.12, + # 3.11.14, 3.10.19, and 3.9.24. The fix slightly changes HTMLParser's + # output, so tests for particularly malformed input must handle both + # old and new results. The check below is temporary until all supported + # Python versions and CI workers include the fix. See: + # https://github.com/python/cpython/commit/6eb6c5db + min_fixed = { + (3, 14): (3, 14), + (3, 13): (3, 13, 6), + (3, 12): (3, 12, 12), + (3, 11): (3, 11, 14), + (3, 10): (3, 10, 19), + (3, 9): (3, 9, 24), + } + htmlparser_fixed = sys.version_info >= min_fixed[sys.version_info[:2]] items = ( ( "

See: 'é is an apostrophe followed by e acute

", @@ -142,10 +158,16 @@ def test_strip_tags(self): ("&gotcha&#;<>", "&gotcha&#;<>"), ("ript>test</script>", "ript>test"), ("&h", "alert()h"), - (">" if htmlparser_fixed else ">br>br>br>X", "XX"), ("<" * 50 + "a>" * 50, ""), - (">" + "" + "" + "" if htmlparser_fixed else ">" + "