diff roundup/cgi/templating.py @ 4391:d5239335fae3

make URL detection a little smarter about brackets per issue2550657 (thanks Ezio Melotti)
author Richard Jones <richard@users.sourceforge.net>
date Mon, 12 Jul 2010 04:14:02 +0000
parents 11d9f3f98897
children 172489ea9e07
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Mon Jul 12 04:11:05 2010 +0000
+++ b/roundup/cgi/templating.py	Mon Jul 12 04:14:02 2010 +0000
@@ -1361,16 +1361,21 @@
             u = s = match.group('url')
             if not self.protocol_re.search(s):
                 u = 'http://' + s
-            # catch an escaped ">" at the end of the URL
             if s.endswith('&gt;'):
+                # catch an escaped ">" at the end of the URL
                 u = s = s[:-4]
                 e = '&gt;'
+            elif s.count('(') != s.count(')'):
+                # don't include extraneous ')' in the link
+                pos = s.rfind(')')
+                e = s[pos:]
+                u = s = s[:pos]
             else:
                 e = ''
-            return '<a href="%s">%s</a>%s'%(u, s, e)
+            return '<a href="%s">%s</a>%s' % (u, s, e)
         elif match.group('email'):
             s = match.group('email')
-            return '<a href="mailto:%s">%s</a>'%(s, s)
+            return '<a href="mailto:%s">%s</a>' % (s, s)
         elif len(match.group('id')) < 10:
             return self._hyper_repl_item(match,
                 '<a href="%(cls)s%(id)s">%(item)s</a>')

Roundup Issue Tracker: http://roundup-tracker.org/