diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2025-12-11 08:44:19 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-01-22 13:43:19 -0500 |
| commit | 7b3e75f73186381a9ec1e7de64e8389aae2e3435 (patch) | |
| tree | 035cb1ed0a9b41ae51a921096df52c64d8cb0140 | |
| parent | c9c473f7cc3bb92bc6b7a54a47660f4acde16f5f (diff) | |
[4.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.py | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py index f755b8cebc..c1786a9799 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 @@ -92,7 +93,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), @@ -100,9 +101,27 @@ class TestUtilsHtml(SimpleTestCase): (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] + 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 = ( ( @@ -130,16 +149,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), |
