Skip to content

Commit 47edcde

Browse files
author
James Socol
committed
Improving link matching and adding tests. Version bump => 0.3.2.
1 parent 1b65da3 commit 47edcde

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

bleach/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
tv tw tz ua ug uk us uy uz va vc ve vg vi vn vu wf ws xn ye yt yu za zm
4242
zw""".split()
4343

44+
TLDS.reverse()
4445

45-
url_re = re.compile(r'\b(?:[\w-]+:/{0,3})?(?<!@)[\w.-]+\.(?:(?:%s)\w*)(?:(?:\/|\?)\S*)?' % u'|'.join(TLDS))
46+
47+
url_re = re.compile(r'\b(?:[\w-]+:/{0,3})?(?<!@)[\w.-]+\.(?:%s)(?:[/?]\S*)?\b' % u'|'.join(TLDS))
4648
proto_re = re.compile(r'^[\w-]+:/{0,3}')
4749

4850

bleach/tests/test_links.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,15 @@ def test_escaped_html():
110110
#def test_link_http_complete():
111111
# eq_('<a href="https://user:pass@ftp.mozilla.com/x/y.exe?a=b&amp;c=d&amp;e#f">https://user:pass@ftp.mozilla.com/x/y.exe?a=b&amp;c=d&amp;e#f</a>',
112112
# b.linkify('https://user:pass@ftp.mozilla.org/x/y.exe?a=b&c=d&e#f'))
113+
114+
115+
def test_non_url():
116+
"""document.vulnerable should absolutely not be linkified."""
117+
s = 'document.vulnerable'
118+
eq_(s, b.linkify(s))
119+
120+
121+
def test_javascript_url():
122+
"""javascript: urls should never be linkified."""
123+
s = 'javascript:document.vulnerable'
124+
eq_(s, b.linkify(s))

setup.py

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

33
setup(
44
name='bleach',
5-
version='0.3.1',
5+
version='0.3.2',
66
description='An easy whitelist-based HTML-sanitizing tool.',
77
long_description=open('README.rst').read(),
88
author='James Socol',

0 commit comments

Comments
 (0)