From c3f98718976820da5123169027612324d09a89d6 Mon Sep 17 00:00:00 2001 From: Natalia <124304+nessita@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:45:03 -0300 Subject: [PATCH] [4.2.x] Fixed #36499 -- Adjusted utils_tests.test_html.TestUtilsHtml.test_strip_tags following Python's HTMLParser new behavior. Python fixed a quadratic complexity processing for HTMLParser in: https://github.com/python/cpython/commit/6eb6c5db. Backport of 2980627502c84a9fd09272e1349dc574a2ff1fb1 from main. --- tests/utils_tests/test_html.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py index 25168e2348..f755b8cebc 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 @@ -85,6 +86,24 @@ class TestUtilsHtml(SimpleTestCase): 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), + } + py_version = sys.version_info[:2] + htmlparser_fixed = ( + py_version in min_fixed and sys.version_info >= min_fixed[py_version] + ) items = ( ( "
See: 'é is an apostrophe followed by e acute
", @@ -112,10 +131,16 @@ class TestUtilsHtml(SimpleTestCase): ("&gotcha<>", "&gotcha<>"), ("