diff --git a/bleach/__init__.py b/bleach/__init__.py index 09f322fa..e80e8d53 100644 --- a/bleach/__init__.py +++ b/bleach/__init__.py @@ -59,7 +59,7 @@ url_re = re.compile( r"""\(* # Match any opening parentheses. \b(?"]*)? # /path/zz (excluding "unsafe" chars from RFC 1738, # except for # and ~, which happen in practice) diff --git a/bleach/tests/test_links.py b/bleach/tests/test_links.py index bcc652ec..948d9997 100644 --- a/bleach/tests/test_links.py +++ b/bleach/tests/test_links.py @@ -242,8 +242,7 @@ def test_sarcasm(): def test_wrapping_parentheses(): - """urls wrapped in balanced paranthesis shall not include them in the href - """ + """URLs wrapped in parantheses should not include them.""" out = u'%s%s%s' tests = ( @@ -277,3 +276,21 @@ def check(test, expected_output): for test, expected_output in tests: yield check, test, expected_output + + +def test_ports(): + """URLs can contain port numbers.""" + tests = ( + ('http://foo.com:8000', ('http://foo.com:8000', '')), + ('http://foo.com:8000/', ('http://foo.com:8000/', '')), + ('http://bar.com:xkcd', ('http://bar.com', ':xkcd')), + ('http://foo.com:81/bar', ('http://foo.com:81/bar', '')), + ('http://foo.com:', ('http://foo.com', ':')), + ) + + def check(test, output): + eq_(u'{0}{1}'.format(*output), + linkify(test)) + + for test, output in tests: + yield check, test, output