|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | from datetime import datetime |
3 | 4 |
|
4 | 5 | from django.core.exceptions import SuspiciousOperation |
@@ -115,6 +116,21 @@ def test_linebreaks(self): |
115 | 116 | self.check_output(linebreaks, lazystr(value), output) |
116 | 117 |
|
117 | 118 | def test_strip_tags(self): |
| 119 | + # Python fixed a quadratic-time issue in HTMLParser in 3.13.6, 3.12.12, |
| 120 | + # 3.11.14, 3.10.19, and 3.9.24. The fix slightly changes HTMLParser's |
| 121 | + # output, so tests for particularly malformed input must handle both |
| 122 | + # old and new results. The check below is temporary until all supported |
| 123 | + # Python versions and CI workers include the fix. See: |
| 124 | + # https://github.com/python/cpython/commit/6eb6c5db |
| 125 | + min_fixed = { |
| 126 | + (3, 14): (3, 14), |
| 127 | + (3, 13): (3, 13, 6), |
| 128 | + (3, 12): (3, 12, 12), |
| 129 | + (3, 11): (3, 11, 14), |
| 130 | + (3, 10): (3, 10, 19), |
| 131 | + (3, 9): (3, 9, 24), |
| 132 | + } |
| 133 | + htmlparser_fixed = sys.version_info >= min_fixed[sys.version_info[:2]] |
118 | 134 | items = ( |
119 | 135 | ( |
120 | 136 | "<p>See: 'é is an apostrophe followed by e acute</p>", |
@@ -142,10 +158,16 @@ def test_strip_tags(self): |
142 | 158 | ("&gotcha&#;<>", "&gotcha&#;<>"), |
143 | 159 | ("<sc<!-- -->ript>test<<!-- -->/script>", "ript>test"), |
144 | 160 | ("<script>alert()</script>&h", "alert()h"), |
145 | | - ("><!" + ("&" * 16000) + "D", "><!" + ("&" * 16000) + "D"), |
| 161 | + ( |
| 162 | + "><!" + ("&" * 16000) + "D", |
| 163 | + ">" if htmlparser_fixed else "><!" + ("&" * 16000) + "D", |
| 164 | + ), |
146 | 165 | ("X<<<<br>br>br>br>X", "XX"), |
147 | 166 | ("<" * 50 + "a>" * 50, ""), |
148 | | - (">" + "<a" * 500 + "a", ">" + "<a" * 500 + "a"), |
| 167 | + ( |
| 168 | + ">" + "<a" * 500 + "a", |
| 169 | + ">" if htmlparser_fixed else ">" + "<a" * 500 + "a", |
| 170 | + ), |
149 | 171 | ("<a" * 49 + "a" * 951, "<a" * 49 + "a" * 951), |
150 | 172 | ("<" + "a" * 1_002, "<" + "a" * 1_002), |
151 | 173 | ) |
|
0 commit comments