[Python-checkins] r83955 - in tracker/roundup-src: roundup/cgi/templating.py test/test_templating.py
ezio.melotti
python-checkins at python.org
Thu Aug 12 09:06:49 CEST 2010
Author: ezio.melotti
Date: Thu Aug 12 09:06:49 2010
New Revision: 83955
Log:
#254: Fix linkification of URLs that contain >. See also Roundup issue #2550664.
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 Thu Aug 12 09:06:49 2010
@@ -1343,18 +1343,18 @@
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')
Modified: tracker/roundup-src/test/test_templating.py
==============================================================================
--- tracker/roundup-src/test/test_templating.py (original)
+++ tracker/roundup-src/test/test_templating.py Thu Aug 12 09:06:49 2010
@@ -146,11 +146,13 @@
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('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('<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)'),
@@ -164,6 +166,12 @@
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>)>.')
+ 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