wrote tests for the convert_urls function of TextToHTMLparser

improved regex to better handle edge cases, particularly a period following the URL
This commit is contained in:
Dan Feeney 2015-11-08 22:35:20 -06:00 committed by Griatch
parent db218f7293
commit ccd1451a02
2 changed files with 81 additions and 2 deletions

View file

@ -81,7 +81,7 @@ class TextToHTMLparser(object):
re_uline = re.compile("(?:%s)(.*?)(?=%s)" % (ANSI_UNDERLINE.replace("[", r"\["), fgstop))
re_string = re.compile(r'(?P<htmlchars>[<&>])|(?P<space> [ \t]+)|(?P<lineend>\r\n|\r|\n)', re.S|re.M|re.I)
re_link = re.compile(r'\{lc(.*?)\{lt(.*?)\{le', re.DOTALL)
re_url = re.compile(r'((ftp|www|https|http)\W+[^"\',;$*^\\()[\]{}<>\s]+)')
re_url = re.compile(r'((?:ftp|www|https?)\W+(?:(?!\.(?:\s|$)|&\w+;)[^"\',;$*^\\(){}<>\[\]\s])+)(\.(?:\s|$)|&\w+;|)')
def re_color(self, text):
"""
@ -184,7 +184,7 @@ class TextToHTMLparser(object):
"""
# -> added target to output prevent the web browser from attempting to
# change pages (and losing our webclient session).
return re_url.sub(r'<a href="\1" target="_blank">\1</a>', text)
return self.re_url.sub(r'<a href="\1" target="_blank">\1</a>\2', text)
def convert_links(self, text):
"""