From c637b9cf44cf267e7883dd4e3ed529ea7b17a004 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Wed, 6 Feb 2013 09:33:24 -0500 Subject: [PATCH] Handle chars at end of link better (imported from commit 53842bc17bbb9cfb555738ee6b72291d7ce61d67) --- zephyr/lib/bugdown/__init__.py | 4 ++-- zephyr/tests.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/zephyr/lib/bugdown/__init__.py b/zephyr/lib/bugdown/__init__.py index 5539e03a5f..cd333a3b33 100644 --- a/zephyr/lib/bugdown/__init__.py +++ b/zephyr/lib/bugdown/__init__.py @@ -161,8 +161,8 @@ class Bugdown(markdown.Extension): # we match at maximum one set of matching parens in a url. We could extend this # to match two parenthetical groups, at the cost of more regex complexity. tlds = '|'.join(['co.uk', 'com', 'co', 'biz', 'gd', 'org', 'net', 'ly', 'edu', 'mil', - 'gov', 'info', 'me', 'it', '.ca', 'tv', 'fm',]) - link_regex = r"\b(?P[^\s]+\.(%s)(?:/[^\s()\"]*|([^\s()\"]*\([^\s()\"]+\)[^\s()\"]*))?)(?=[\s:;\?\),\.\'\"]|\Z)" % (tlds,) + 'gov', 'info', 'me', 'it', '.ca', 'tv', 'fm', 'io', 'gl']) + link_regex = r"\b(?P[^\s]+\.(%s)(?:/[^\s()\":]*?|([^\s()\":]*\([^\s()\":]*\)[^\s()\":]*))?)(?=([:;\?\),\.\'\"]\Z|[:;\?\),\.\'\"]\s|\Z|\s))" % (tlds,) md.inlinePatterns.add('autolink', AutoLink(link_regex), '>link') md.preprocessors.add('hanging_ulists', diff --git a/zephyr/tests.py b/zephyr/tests.py index 72b4a3d0e3..30c2e8c25a 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -1754,6 +1754,11 @@ int x = 3 ('(Something like http://foo.com/blah_blah)', "

(Something like %s)

", 'http://foo.com/blah_blah'), ('"is.gd/foo/"', "

\"%s\"

", 'is.gd/foo/'), ('end with a quote www.google.com"', "

end with a quote %s\"

", 'www.google.com'), + ('http://www.guardian.co.uk/foo/bar', "

%s

", 'http://www.guardian.co.uk/foo/bar'), + ('from http://supervisord.org/running.html:', "

from %s:

", 'http://supervisord.org/running.html'), + ('http://raven.io', "

%s

", 'http://raven.io'), + ('at https://humbughq.com/api. Check it!', "

at %s. Check it!

", 'https://humbughq.com/api'), + ('goo.gl/abc', "

%s

", 'goo.gl/abc'), # XSS Sanitization ('javascript:alert(\'hi\');.com', "

%s

", None), # None marks xss @@ -1765,11 +1770,14 @@ int x = 3 ('http://leo@foo.com/my/file', "

%s

", None), ('http://example.com/something?with,commas,in,url, but not at end', - "

%s but not at end

", 'http://example.com/something?with,commas,in,url,'), + "

%s, but not at end

", 'http://example.com/something?with,commas,in,url'), (' some text https://www.google.com/baz_(match)?with=foo&bar=baz with extras', "

some text %s with extras

", 'https://www.google.com/baz_(match)?with=foo&bar=baz'), ('hash it http://foo.com/blah_(wikipedia)_blah#cite-1', - "

hash it %s

", 'http://foo.com/blah_(wikipedia)_blah#cite-1'),] + "

hash it %s

", 'http://foo.com/blah_(wikipedia)_blah#cite-1'), + ('http://technet.microsoft.com/en-us/library/Cc751099.rk20_25_big(l=en-us).gif', + "

%s

", + 'http://technet.microsoft.com/en-us/library/Cc751099.rk20_25_big(l=en-us).gif')] for inline_url, reference, url in conversions: try: