Code

make URL detection a little smarter about brackets per issue2550657 (thanks Ezio...
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 12 Jul 2010 04:14:02 +0000 (04:14 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 12 Jul 2010 04:14:02 +0000 (04:14 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4497 57a73879-2fb5-44c3-a270-3262357dd7e2

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

index d0338316a6f877ed51d4d951704b8fee9fac209d..8e063f50afc61f1eda52b33fb8f7bce1c2cb1fc6 100644 (file)
@@ -6,6 +6,8 @@ are given with the most recent entry first.
 Fixed:
 - A bunch of regressions were introduced in the last release making Roundup
   no longer work in Python releases prior to 2.6
+- make URL detection a little smarter about brackets per issue2550657
+  (thanks Ezio Melotti)
 
 
 2010-07-01 1.4.14
index b6b7ccc958f2d714308fefba105affac9c5334d0..ddeec33d88068ad000aa356ee0bfb9e3eaac886b 100644 (file)
@@ -84,6 +84,7 @@ Georges Martin,
 Gordon McMillan,
 John F Meinel Jr,
 Roland Meister,
+Ezio Melotti,
 Ulrik Mikaelsson,
 John Mitchell,
 Ramiro Morales,
index 271955e52df9612b442e5591f475a7fd92560a4f..6296a137651edb73853c3b4e50837e9c2b28f260 100644 (file)
@@ -1361,16 +1361,21 @@ class StringHTMLProperty(HTMLProperty):
             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>')
index ad6d7585ac94ee37522bc94d37b4f3edefc0462d..d176842d4c7fcc8be07458103b37935a7a8aa979 100644 (file)
@@ -147,10 +147,24 @@ class HTMLClassTestCase(TemplatingTestCase) :
         p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')
         def t(s): return p.hyper_re.sub(p._hyper_repl, s)
         ae = self.assertEquals
-        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;www.roundup.net&gt;'), '&lt;<a href="http://www.roundup.net">www.roundup.net</a>&gt;')
         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;www.roundup.net&gt;'),
+           '&lt;<a href="http://www.roundup.net">www.roundup.net</a>&gt;')
+        ae(t('(www.roundup.net)'),
+           '(<a href="http://www.roundup.net">www.roundup.net</a>)')
+        ae(t('foo http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx bar'),
+           'foo <a href="http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx">'
+           'http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx</a> bar')
+        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)).'),
+           '(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)">'
+           'http://en.wikipedia.org/wiki/Python_(programming_language)</a>).')
 
 '''
 class HTMLPermissions: