Skip to content

Commit ba3fd73

Browse files
committed
Deprecate the sanitizer and recommend Bleach
1 parent d49afd3 commit ba3fd73

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

CHANGES.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ Breaking changes:
1111
* Drop support for Python 3.3. (#358)
1212
* Drop support for Python 3.4. (#421)
1313

14+
Deprecations:
15+
16+
* Deprecate the ``html5lib`` sanitizer (``html5lib.serialize(sanitize=True)`` and
17+
``html5lib.filters.sanitizer``). We recommend users migrate to `Bleach
18+
<https://github.com/mozilla/bleach>`. Please let us know if Bleach doesn't suffice for your
19+
use. (#443)
20+
1421
Other changes:
1522

16-
* Try to import from `collections.abc` to remove DeprecationWarning and ensure
17-
`html5lib` keeps working in future Python versions. (#403)
18-
* Drop optional `datrie` dependency. (#442)
23+
* Try to import from ``collections.abc`` to remove DeprecationWarning and ensure
24+
``html5lib`` keeps working in future Python versions. (#403)
25+
* Drop optional ``datrie`` dependency. (#442)
1926

2027

2128
1.0.1

html5lib/filters/sanitizer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import, division, unicode_literals
22

33
import re
4+
import warnings
45
from xml.sax.saxutils import escape, unescape
56

67
from six.moves import urllib_parse as urlparse
@@ -11,6 +12,13 @@
1112
__all__ = ["Filter"]
1213

1314

15+
warnings.warn(
16+
"html5lib's sanitizer is deprecated; see " +
17+
"https://github.com/html5lib/html5lib-python/issues/443 and please let " +
18+
"us know if Bleach in unsuitable for your needs",
19+
DeprecationWarning
20+
)
21+
1422
allowed_elements = frozenset((
1523
(namespaces['html'], 'a'),
1624
(namespaces['html'], 'abbr'),
@@ -750,6 +758,14 @@ def __init__(self,
750758
751759
"""
752760
super(Filter, self).__init__(source)
761+
762+
warnings.warn(
763+
"html5lib's sanitizer is deprecated; see " +
764+
"https://github.com/html5lib/html5lib-python/issues/443 and please let " +
765+
"us know if Bleach in unsuitable for your needs",
766+
DeprecationWarning
767+
)
768+
753769
self.allowed_elements = allowed_elements
754770
self.allowed_attributes = allowed_attributes
755771
self.allowed_css_properties = allowed_css_properties

html5lib/tests/sanitizer.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ def runtest(self):
2727
expected = self.test["output"]
2828

2929
parsed = parseFragment(input)
30-
serialized = serialize(parsed,
31-
sanitize=True,
32-
omit_optional_tags=False,
33-
use_trailing_solidus=True,
34-
space_before_trailing_solidus=False,
35-
quote_attr_values="always",
36-
quote_char="'",
37-
alphabetical_attributes=True)
30+
with pytest.deprecated_call():
31+
serialized = serialize(parsed,
32+
sanitize=True,
33+
omit_optional_tags=False,
34+
use_trailing_solidus=True,
35+
space_before_trailing_solidus=False,
36+
quote_attr_values="always",
37+
quote_char="'",
38+
alphabetical_attributes=True)
3839
errorMsg = "\n".join(["\n\nInput:", input,
3940
"\nExpected:", expected,
4041
"\nReceived:", serialized])

html5lib/tests/test_sanitizer.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
def sanitize_html(stream):
1010
parsed = parseFragment(stream)
11-
serialized = serialize(parsed,
12-
sanitize=True,
13-
omit_optional_tags=False,
14-
use_trailing_solidus=True,
15-
space_before_trailing_solidus=False,
16-
quote_attr_values="always",
17-
quote_char='"',
18-
alphabetical_attributes=True)
11+
with pytest.deprecated_call():
12+
serialized = serialize(parsed,
13+
sanitize=True,
14+
omit_optional_tags=False,
15+
use_trailing_solidus=True,
16+
space_before_trailing_solidus=False,
17+
quote_attr_values="always",
18+
quote_char='"',
19+
alphabetical_attributes=True)
1920
return serialized
2021

2122

0 commit comments

Comments
 (0)