Mercurial > p > roundup > code
changeset 4391:d5239335fae3
make URL detection a little smarter about brackets per issue2550657
(thanks Ezio Melotti)
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 12 Jul 2010 04:14:02 +0000 |
| parents | 936bd9bf732d |
| children | 05eb6a596636 |
| files | CHANGES.txt doc/acknowledgements.txt roundup/cgi/templating.py test/test_templating.py |
| diffstat | 4 files changed, 28 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Mon Jul 12 04:11:05 2010 +0000 +++ b/CHANGES.txt Mon Jul 12 04:14:02 2010 +0000 @@ -6,6 +6,8 @@ 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
--- a/doc/acknowledgements.txt Mon Jul 12 04:11:05 2010 +0000 +++ b/doc/acknowledgements.txt Mon Jul 12 04:14:02 2010 +0000 @@ -84,6 +84,7 @@ Gordon McMillan, John F Meinel Jr, Roland Meister, +Ezio Melotti, Ulrik Mikaelsson, John Mitchell, Ramiro Morales,
--- a/roundup/cgi/templating.py Mon Jul 12 04:11:05 2010 +0000 +++ b/roundup/cgi/templating.py Mon Jul 12 04:14:02 2010 +0000 @@ -1361,16 +1361,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>')
--- a/test/test_templating.py Mon Jul 12 04:11:05 2010 +0000 +++ b/test/test_templating.py Mon Jul 12 04:14:02 2010 +0000 @@ -147,10 +147,24 @@ 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('item123123123123'), 'item123123123123') + 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:
