|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | from datetime import datetime |
3 | 4 |
|
4 | 5 | from django.core.exceptions import SuspiciousOperation |
@@ -85,6 +86,24 @@ def test_linebreaks(self): |
85 | 86 | self.check_output(linebreaks, lazystr(value), output) |
86 | 87 |
|
87 | 88 | def test_strip_tags(self): |
| 89 | + # Python fixed a quadratic-time issue in HTMLParser in 3.13.6, 3.12.12, |
| 90 | + # 3.11.14, 3.10.19, and 3.9.24. The fix slightly changes HTMLParser's |
| 91 | + # output, so tests for particularly malformed input must handle both |
| 92 | + # old and new results. The check below is temporary until all supported |
| 93 | + # Python versions and CI workers include the fix. See: |
| 94 | + # https://github.com/python/cpython/commit/6eb6c5db |
| 95 | + min_fixed = { |
| 96 | + (3, 14): (3, 14), |
| 97 | + (3, 13): (3, 13, 6), |
| 98 | + (3, 12): (3, 12, 12), |
| 99 | + (3, 11): (3, 11, 14), |
| 100 | + (3, 10): (3, 10, 19), |
| 101 | + (3, 9): (3, 9, 24), |
| 102 | + } |
| 103 | + py_version = sys.version_info[:2] |
| 104 | + htmlparser_fixed = ( |
| 105 | + py_version in min_fixed and sys.version_info >= min_fixed[py_version] |
| 106 | + ) |
88 | 107 | items = ( |
89 | 108 | ( |
90 | 109 | "<p>See: 'é is an apostrophe followed by e acute</p>", |
@@ -112,10 +131,16 @@ def test_strip_tags(self): |
112 | 131 | ("&gotcha&#;<>", "&gotcha&#;<>"), |
113 | 132 | ("<sc<!-- -->ript>test<<!-- -->/script>", "ript>test"), |
114 | 133 | ("<script>alert()</script>&h", "alert()h"), |
115 | | - ("><!" + ("&" * 16000) + "D", "><!" + ("&" * 16000) + "D"), |
| 134 | + ( |
| 135 | + "><!" + ("&" * 16000) + "D", |
| 136 | + ">" if htmlparser_fixed else "><!" + ("&" * 16000) + "D", |
| 137 | + ), |
116 | 138 | ("X<<<<br>br>br>br>X", "XX"), |
117 | 139 | ("<" * 50 + "a>" * 50, ""), |
118 | | - (">" + "<a" * 500 + "a", ">" + "<a" * 500 + "a"), |
| 140 | + ( |
| 141 | + ">" + "<a" * 500 + "a", |
| 142 | + ">" if htmlparser_fixed else ">" + "<a" * 500 + "a", |
| 143 | + ), |
119 | 144 | ("<a" * 49 + "a" * 951, "<a" * 49 + "a" * 951), |
120 | 145 | ("<" + "a" * 1_002, "<" + "a" * 1_002), |
121 | 146 | ) |
|
0 commit comments