Skip to content

Commit 8df6cc9

Browse files
authored
Deprecate the sanitizer and recommend Bleach (#501)
1 parent 7e52b16 commit 8df6cc9

File tree

4 files changed

+48
-19
lines changed

4 files changed

+48
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
"""Deprecated from html5lib 1.1.
2+
3+
See `here <https://github.com/html5lib/html5lib-python/issues/443>`_ for
4+
information about its deprecation; `Bleach <https://github.com/mozilla/bleach>`_
5+
is recommended as a replacement. Please let us know in the aforementioned issue
6+
if Bleach is unsuitable for your needs.
7+
8+
"""
19
from __future__ import absolute_import, division, unicode_literals
210

311
import re
12+
import warnings
413
from xml.sax.saxutils import escape, unescape
514

615
from six.moves import urllib_parse as urlparse
@@ -11,6 +20,14 @@
1120
__all__ = ["Filter"]
1221

1322

23+
_deprecation_msg = (
24+
"html5lib's sanitizer is deprecated; see " +
25+
"https://github.com/html5lib/html5lib-python/issues/443 and please let " +
26+
"us know if Bleach is unsuitable for your needs"
27+
)
28+
29+
warnings.warn(_deprecation_msg, DeprecationWarning)
30+
1431
allowed_elements = frozenset((
1532
(namespaces['html'], 'a'),
1633
(namespaces['html'], 'abbr'),
@@ -750,6 +767,9 @@ def __init__(self,
750767
751768
"""
752769
super(Filter, self).__init__(source)
770+
771+
warnings.warn(_deprecation_msg, DeprecationWarning)
772+
753773
self.allowed_elements = allowed_elements
754774
self.allowed_attributes = allowed_attributes
755775
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy