summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNatalia <124304+nessita@users.noreply.github.com>2025-07-14 14:45:03 -0300
committernessita <124304+nessita@users.noreply.github.com>2025-08-13 17:48:37 -0300
commit9a720d5c5000b4fe0e75cdb87271065b5e80dedc (patch)
treef0de0473caefa4512c2c750a5d33a3d32b489e68 /tests
parent74fafe2715fa2569a1682defcedc12a2e03b13d1 (diff)
[5.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.
Diffstat (limited to 'tests')
-rw-r--r--tests/utils_tests/test_html.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index caf6598b3d..681071bf03 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
@@ -117,6 +118,21 @@ 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),
+ }
+ htmlparser_fixed = sys.version_info >= min_fixed[sys.version_info[:2]]
items = (
(
"<p>See: &#39;&eacute; is an apostrophe followed by e acute</p>",
@@ -144,10 +160,16 @@ class TestUtilsHtml(SimpleTestCase):
("&gotcha&#;<>", "&gotcha&#;<>"),
("<sc<!-- -->ript>test<<!-- -->/script>", "ript>test"),
("<script>alert()</script>&h", "alert()h"),
- ("><!" + ("&" * 16000) + "D", "><!" + ("&" * 16000) + "D"),
+ (
+ "><!" + ("&" * 16000) + "D",
+ ">" if htmlparser_fixed else "><!" + ("&" * 16000) + "D",
+ ),
("X<<<<br>br>br>br>X", "XX"),
("<" * 50 + "a>" * 50, ""),
- (">" + "<a" * 500 + "a", ">" + "<a" * 500 + "a"),
+ (
+ ">" + "<a" * 500 + "a",
+ ">" if htmlparser_fixed else ">" + "<a" * 500 + "a",
+ ),
("<a" * 49 + "a" * 951, "<a" * 49 + "a" * 951),
("<" + "a" * 1_002, "<" + "a" * 1_002),
)