[Python-checkins] r82525 - in tracker/roundup-src: roundup/cgi/templating.py test/test_templating.py
ezio.melotti
python-checkins at python.org
Sun Jul 4 03:35:45 CEST 2010
Author: ezio.melotti
Date: Sun Jul 4 03:35:45 2010
New Revision: 82525
Log:
#254: now URLs inside parentheses (e.g. www.python.org) are linkified properly.
Modified:
tracker/roundup-src/roundup/cgi/templating.py
tracker/roundup-src/test/test_templating.py
Modified: tracker/roundup-src/roundup/cgi/templating.py
==============================================================================
--- tracker/roundup-src/roundup/cgi/templating.py (original)
+++ tracker/roundup-src/roundup/cgi/templating.py Sun Jul 4 03:35:45 2010
@@ -1343,16 +1343,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('>'):
+ # catch an escaped ">" at the end of the URL
u = s = s[:-4]
e = '>'
+ 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>')
Modified: tracker/roundup-src/test/test_templating.py
==============================================================================
--- tracker/roundup-src/test/test_templating.py (original)
+++ tracker/roundup-src/test/test_templating.py Sun Jul 4 03:35:45 2010
@@ -147,9 +147,23 @@
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('<HTTP://roundup.net/>'), '<<a href="HTTP://roundup.net/">HTTP://roundup.net/</a>>')
- ae(t('<www.roundup.net>'), '<<a href="http://www.roundup.net">www.roundup.net</a>>')
+ ae(t('http://roundup.net/'),
+ '<a href="http://roundup.net/">http://roundup.net/</a>')
+ ae(t('<HTTP://roundup.net/>'),
+ '<<a href="HTTP://roundup.net/">HTTP://roundup.net/</a>>')
+ ae(t('<www.roundup.net>'),
+ '<<a href="http://www.roundup.net">www.roundup.net</a>>')
+ 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:
More information about the Python-checkins
mailing list