|
1 | 1 | from __future__ import unicode_literals
|
2 | 2 |
|
3 | 3 | from functools import partial
|
| 4 | +from timeit import timeit |
4 | 5 |
|
5 | 6 | import pytest
|
6 | 7 |
|
|
37 | 38 | '<p style="color: red;">bar</p>'
|
38 | 39 | ),
|
39 | 40 | # Handle leading - in attributes
|
40 |
| - ( |
| 41 | + # regressed with the fix for bug 1623633 |
| 42 | + pytest.param( |
41 | 43 | '<p style="cursor: -moz-grab;">bar</p>',
|
42 | 44 | ['cursor'],
|
43 |
| - '<p style="cursor: -moz-grab;">bar</p>' |
| 45 | + '<p style="cursor: -moz-grab;">bar</p>', |
| 46 | + marks=pytest.mark.xfail, |
44 | 47 | ),
|
45 | 48 | # Handle () in attributes
|
46 | 49 | (
|
|
54 | 57 | '<p style="color: rgba(255,0,0,0.4);">bar</p>',
|
55 | 58 | ),
|
56 | 59 | # Handle ' in attributes
|
57 |
| - ( |
| 60 | + # regressed with the fix for bug 1623633 |
| 61 | + pytest.param( |
58 | 62 | '<p style="text-overflow: \',\' ellipsis;">bar</p>',
|
59 | 63 | ['text-overflow'],
|
60 |
| - '<p style="text-overflow: \',\' ellipsis;">bar</p>' |
| 64 | + '<p style="text-overflow: \',\' ellipsis;">bar</p>', |
| 65 | + marks=pytest.mark.xfail, |
61 | 66 | ),
|
62 | 67 | # Handle " in attributes
|
63 |
| - ( |
| 68 | + # regressed with the fix for bug 1623633 |
| 69 | + pytest.param( |
64 | 70 | '<p style=\'text-overflow: "," ellipsis;\'>bar</p>',
|
65 | 71 | ['text-overflow'],
|
66 |
| - '<p style=\'text-overflow: "," ellipsis;\'>bar</p>' |
| 72 | + '<p style=\'text-overflow: "," ellipsis;\'>bar</p>', |
| 73 | + marks=pytest.mark.xfail, |
67 | 74 | ),
|
68 | 75 | (
|
69 | 76 | '<p style=\'font-family: "Arial";\'>bar</p>',
|
@@ -223,3 +230,17 @@ def test_style_hang():
|
223 | 230 | def test_css_parsing_with_entities(data, styles, expected):
|
224 | 231 | """The sanitizer should be ok with character entities"""
|
225 | 232 | assert clean(data, tags=['p'], attributes={'p': ['style']}, styles=styles) == expected
|
| 233 | + |
| 234 | + |
| 235 | +@pytest.mark.parametrize('overlap_test_char', ["\"", "'", "-"]) |
| 236 | +def test_css_parsing_gauntlet_regex_backtracking(overlap_test_char): |
| 237 | + """The sanitizer gauntlet regex should not catastrophically backtrack""" |
| 238 | + # refs: https://bugzilla.mozilla.org/show_bug.cgi?id=1623633 |
| 239 | + |
| 240 | + def time_clean(test_char, size): |
| 241 | + style_attr_value = (test_char + 'a' + test_char) * size + '^' |
| 242 | + stmt = """clean('''<a style='%s'></a>''', attributes={'a': ['style']})""" % style_attr_value |
| 243 | + return timeit(stmt=stmt, setup='from bleach import clean', number=1) |
| 244 | + |
| 245 | + # should complete in less than one second |
| 246 | + assert time_clean(overlap_test_char, 22) < 1.0 |
0 commit comments