Skip to content

Commit 26b40d1

Browse files
committed
Merge branch 'feature/ammonia' into develop
2 parents 8a5053e + a47bd97 commit 26b40d1

6 files changed

Lines changed: 12 additions & 22 deletions

File tree

README.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ h2. Installation
99
@pip install textile@
1010

1111
Dependencies:
12-
* "html5lib":https://pypi.org/project/html5lib/
12+
* "nh3":https://pypi.org/project/nh3/
1313
* "regex":https://pypi.org/project/regex/ (The regex package causes problems with PyPy, and is not installed as a dependency in such environments. If you are upgrading a textile install on PyPy which had regex previously included, you may need to uninstall it.)
1414

1515
Optional dependencies include:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools", "setuptools-scm"]
2+
requires = ["setuptools", "setuptools-scm", "nh3"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -26,7 +26,7 @@ classifiers = [
2626
]
2727
dynamic = ["version",]
2828
dependencies = [
29-
'html5lib>=1.0.1',
29+
'nh3',
3030
'regex>1.0; implementation_name != "pypy"',
3131
]
3232
requires-python = '>=3.8'

tests/fixtures/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<p>Dependencies:
1212
<ul>
13-
<li><a href="https://pypi.org/project/html5lib/">html5lib</a></li>
13+
<li><a href="https://pypi.org/project/nh3/">nh3</a></li>
1414
<li><a href="https://pypi.org/project/regex/">regex</a> (The regex package causes problems with PyPy, and is not installed as a dependency in such environments. If you are upgrading a textile install on PyPy which had regex previously included, you may need to uninstall it.)</li>
1515
</ul></p>
1616

tests/test_textile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_sanitize():
117117
assert result == expect
118118

119119
test = """<p style="width: expression(alert('evil'));">a paragraph of evil text</p>"""
120-
result = '<p style="">a paragraph of evil text</p>'
120+
result = '<p>a paragraph of evil text</p>'
121121
expect = textile.Textile().parse(test, sanitize=True)
122122
assert result == expect
123123

textile/core.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
import uuid
2121
from urllib.parse import urlparse, urlsplit, urlunsplit, quote, unquote
2222
from collections import OrderedDict
23+
from nh3 import clean
2324

24-
from textile.tools import sanitizer, imagesize
25+
from textile.tools import imagesize
2526
from textile.regex_strings import (align_re_s, cls_re_s, pnct_re_s,
2627
regex_snippets, syms_re_s, table_span_re_s)
2728
from textile.utils import (decode_high, encode_high, encode_html, generate_tag,
@@ -236,12 +237,12 @@ def parse(self, text, rel=None, sanitize=False):
236237

237238
if self.block_tags:
238239
if self.lite:
239-
self.blocktag_whitelist = ['bq', 'p']
240+
self.blocktag_allowlist = set(['bq', 'p', 'br'])
240241
text = self.block(text)
241242
else:
242-
self.blocktag_whitelist = ['bq', 'p', 'bc', 'notextile',
243-
'pre', 'h[1-6]', 'fn{0}+'.format(
244-
regex_snippets['digit']), '###']
243+
self.blocktag_allowlist = set(['bq', 'p', 'br', 'bc', 'notextile',
244+
'pre', 'h[1-6]',
245+
f"fn{regex_snippets['digit']}+", '###'])
245246
text = self.block(text)
246247
text = self.placeNoteLists(text)
247248
else:
@@ -263,7 +264,7 @@ def parse(self, text, rel=None, sanitize=False):
263264
text = text.replace('{0}:glyph:'.format(self.uid), '')
264265

265266
if sanitize:
266-
text = sanitizer.sanitize(text)
267+
text = clean(text, tags=self.blocktag_allowlist)
267268

268269
text = self.retrieveTags(text)
269270
text = self.retrieveURLs(text)

textile/tools/sanitizer.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)