From fae9c7a706e2ecac32a2634b6ce3e2bfc830b42e Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 12 Jul 2010 04:14:02 +0000 Subject: [PATCH] make URL detection a little smarter about brackets per issue2550657 (thanks Ezio Melotti) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4497 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 2 ++ doc/acknowledgements.txt | 1 + roundup/cgi/templating.py | 11 ++++++++--- test/test_templating.py | 20 +++++++++++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d033831..8e063f5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/doc/acknowledgements.txt b/doc/acknowledgements.txt index b6b7ccc..ddeec33 100644 --- a/doc/acknowledgements.txt +++ b/doc/acknowledgements.txt @@ -84,6 +84,7 @@ Georges Martin, Gordon McMillan, John F Meinel Jr, Roland Meister, +Ezio Melotti, Ulrik Mikaelsson, John Mitchell, Ramiro Morales, diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index 271955e..6296a13 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -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('>'): + # 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 '%s%s'%(u, s, e) + return '%s%s' % (u, s, e) elif match.group('email'): s = match.group('email') - return '%s'%(s, s) + return '%s' % (s, s) elif len(match.group('id')) < 10: return self._hyper_repl_item(match, '%(item)s') diff --git a/test/test_templating.py b/test/test_templating.py index ad6d758..d176842 100644 --- a/test/test_templating.py +++ b/test/test_templating.py @@ -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/'), 'http://roundup.net/') - ae(t('<HTTP://roundup.net/>'), '<HTTP://roundup.net/>') - ae(t('<www.roundup.net>'), '<www.roundup.net>') ae(t('item123123123123'), 'item123123123123') + ae(t('http://roundup.net/'), + 'http://roundup.net/') + ae(t('<HTTP://roundup.net/>'), + '<HTTP://roundup.net/>') + ae(t('<www.roundup.net>'), + '<www.roundup.net>') + ae(t('(www.roundup.net)'), + '(www.roundup.net)') + ae(t('foo http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx bar'), + 'foo ' + 'http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx bar') + ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language))'), + '(e.g. ' + 'http://en.wikipedia.org/wiki/Python_(programming_language))') + ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language)).'), + '(e.g. ' + 'http://en.wikipedia.org/wiki/Python_(programming_language)).') ''' class HTMLPermissions: -- 2.30.2