Code

improve handling of '>' when URLs are converted to links, issue2550664 (thanks...
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Thu, 12 Aug 2010 05:00:07 +0000 (05:00 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Thu, 12 Aug 2010 05:00:07 +0000 (05:00 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4519 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/cgi/templating.py
test/test_templating.py

index 675e0c615cfbcd760eec72a581ae99faf2dadb06..d0a8950e6cfb78a51d98411573ad0e46bf747989 100644 (file)
@@ -22,6 +22,8 @@ Fixed:
 - fix for incorrect except: syntax, issue2550661 (thanks Jakub Wilk)
 - No longer use the root logger, use a logger with prefix "roundup",
   see http://thread.gmane.org/gmane.comp.bug-tracking.roundup.devel/5356
+- improve handling of '&gt;' when URLs are converted to links, issue2550664
+  (thanks Ezio Melotti)
 
 
 2010-07-12 1.4.15
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('&gt;'):
-            # catch an escaped ">" at the end of the URL
-            u = s = s[:-4]
-            e = '&gt;'
-        elif s.count('(') != s.count(')'):
+        end = ''
+        if '&gt;' in s:
+            # catch an escaped ">" in the URL
+            pos = s.find('&gt;')
+            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')
index d176842d4c7fcc8be07458103b37935a7a8aa979..e4244d1da4d24a40cda17a38da8d771a89ff0d3e 100644 (file)
@@ -146,12 +146,14 @@ class HTMLClassTestCase(TemplatingTestCase) :
     def test_url_replace(self):
         p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')
         def t(s): return p.hyper_re.sub(p._hyper_repl, s)
-        ae = self.assertEquals
+        ae = self.assertEqual
         ae(t('item123123123123'), 'item123123123123')
         ae(t('http://roundup.net/'),
            '<a href="http://roundup.net/">http://roundup.net/</a>')
         ae(t('&lt;HTTP://roundup.net/&gt;'),
            '&lt;<a href="HTTP://roundup.net/">HTTP://roundup.net/</a>&gt;')
+         ae(t('&lt;http://roundup.net/&gt;.'),
+            '&lt;<a href="http://roundup.net/">http://roundup.net/</a>&gt;.')
         ae(t('&lt;www.roundup.net&gt;'),
            '&lt;<a href="http://www.roundup.net">www.roundup.net</a>&gt;')
         ae(t('(www.roundup.net)'),
@@ -165,6 +167,12 @@ class HTMLClassTestCase(TemplatingTestCase) :
         ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language)).'),
            '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)">'
            'http://en.wikipedia.org/wiki/Python_(programming_language)</a>).')
+        ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language))&gt;.'),
+           '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)">'
+           'http://en.wikipedia.org/wiki/Python_(programming_language)</a>)&gt;.')
+        ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language&gt;)).'),
+           '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language">'
+           'http://en.wikipedia.org/wiki/Python_(programming_language</a>&gt;)).')
 
 '''
 class HTMLPermissions: