Code

improve handling of '>' when URLs are converted to links, issue2550664 (thanks...
[roundup.git] / roundup / cgi / templating.py
index 9176420f55abedd00debfb8553b1880df259f26b..a08dbcd85729d055777098c8e9e9174f91a17d00 100644 (file)
@@ -1361,18 +1361,18 @@ class StringHTMLProperty(HTMLProperty):
         u = s = match.group('url')
         if not self.protocol_re.search(s):
             u = 'http://' + s
-        if s.endswith('>'):
-            # catch an escaped ">" at the end of the URL
-            u = s = s[:-4]
-            e = '>'
-        elif s.count('(') != s.count(')'):
+        end = ''
+        if '>' in s:
+            # catch an escaped ">" in the URL
+            pos = s.find('>')
+            end = s[pos:]
+            u = s = s[:pos]
+        if ')' in s and s.count('(') != s.count(')'):
             # don't include extraneous ')' in the link
             pos = s.rfind(')')
-            e = s[pos:]
+            end = s[pos:] + end
             u = s = s[:pos]
-        else:
-            e = ''
-        return replacement % (u, s, e)
+        return replacement % (u, s, end)
 
     def _hyper_repl_email(self, match, replacement):
         s = match.group('email')