summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-12-11 08:44:19 -0500
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-11 11:37:31 -0500
commit5ca0f62213911a77dd4a62e843db7e420cc98b78 (patch)
tree7bdc83c32f87886b77e178dca4f197ec61faebb6
parent322b717af5d0e7a13da48aa6a7fd21f52e78896e (diff)
[5.2.x] Refs #36499 -- Adjusted test_strip_tags following Python behavior change for incomplete entities.
Backport of 7b80b2186300620931009fd62c2969f108fe7a62 from main.
-rw-r--r--tests/utils_tests/test_html.py35
1 files changed, 30 insertions, 5 deletions
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index 681071bf03..89c97cee03 100644
--- a/tests/utils_tests/test_html.py
+++ b/tests/utils_tests/test_html.py
@@ -1,3 +1,4 @@
+import math
import os
import sys
from datetime import datetime
@@ -124,7 +125,7 @@ class TestUtilsHtml(SimpleTestCase):
# 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 = {
+ min_fixed_security = {
(3, 14): (3, 14),
(3, 13): (3, 13, 6),
(3, 12): (3, 12, 12),
@@ -132,7 +133,28 @@ class TestUtilsHtml(SimpleTestCase):
(3, 10): (3, 10, 19),
(3, 9): (3, 9, 24),
}
- htmlparser_fixed = sys.version_info >= min_fixed[sys.version_info[:2]]
+ htmlparser_fixed_security = (
+ sys.version_info >= min_fixed_security[sys.version_info[:2]]
+ )
+ # Similarly, there was a fix for terminating incomplete entities. See:
+ # https://github.com/python/cpython/commit/95296a9d
+ min_fixed_incomplete_entities = {
+ (3, 14): (3, 14, 1),
+ (3, 13): (3, 13, 10),
+ # Not fixed in the following versions.
+ (3, 12): (3, 12, math.inf),
+ (3, 11): (3, 11, math.inf),
+ (3, 10): (3, 10, math.inf),
+ (3, 9): (3, 9, math.inf),
+ }
+ major_version = sys.version_info[:2]
+ htmlparser_fixed_security = sys.version_info >= min_fixed_security.get(
+ major_version, major_version
+ )
+ htmlparser_fixed_incomplete_entities = (
+ sys.version_info
+ >= min_fixed_incomplete_entities.get(major_version, major_version)
+ )
items = (
(
"<p>See: &#39;&eacute; is an apostrophe followed by e acute</p>",
@@ -159,16 +181,19 @@ class TestUtilsHtml(SimpleTestCase):
# https://bugs.python.org/issue20288
("&gotcha&#;<>", "&gotcha&#;<>"),
("<sc<!-- -->ript>test<<!-- -->/script>", "ript>test"),
- ("<script>alert()</script>&h", "alert()h"),
+ (
+ "<script>alert()</script>&h",
+ "alert()&h;" if htmlparser_fixed_incomplete_entities else "alert()h",
+ ),
(
"><!" + ("&" * 16000) + "D",
- ">" if htmlparser_fixed else "><!" + ("&" * 16000) + "D",
+ ">" if htmlparser_fixed_security else "><!" + ("&" * 16000) + "D",
),
("X<<<<br>br>br>br>X", "XX"),
("<" * 50 + "a>" * 50, ""),
(
">" + "<a" * 500 + "a",
- ">" if htmlparser_fixed else ">" + "<a" * 500 + "a",
+ ">" if htmlparser_fixed_security else ">" + "<a" * 500 + "a",
),
("<a" * 49 + "a" * 951, "<a" * 49 + "a" * 951),
("<" + "a" * 1_002, "<" + "a" * 1_002),