From 04d91aed9c9def266db9ec49cc32084705bd1fa1 Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 12 Aug 2010 05:00:07 +0000 Subject: [PATCH] improve handling of '>' when URLs are converted to links, issue2550664 (thanks Ezio Melotti) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4519 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 2 ++ roundup/cgi/templating.py | 18 +++++++++--------- test/test_templating.py | 10 +++++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 675e0c6..d0a8950 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -22,6 +22,8 @@ Fixed: - fix for incorrect except: syntax, issue2550661 (thanks Jakub Wilk) - No longer use the root logger, use a logger with prefix "roundup", see http://thread.gmane.org/gmane.comp.bug-tracking.roundup.devel/5356 +- improve handling of '>' when URLs are converted to links, issue2550664 + (thanks Ezio Melotti) 2010-07-12 1.4.15 diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index 9176420..a08dbcd 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -1361,18 +1361,18 @@ class StringHTMLProperty(HTMLProperty): 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') diff --git a/test/test_templating.py b/test/test_templating.py index d176842..e4244d1 100644 --- a/test/test_templating.py +++ b/test/test_templating.py @@ -146,12 +146,14 @@ class HTMLClassTestCase(TemplatingTestCase) : 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('item123123123123'), 'item123123123123') ae(t('http://roundup.net/'), 'http://roundup.net/') 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)'), @@ -165,6 +167,12 @@ class HTMLClassTestCase(TemplatingTestCase) : 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))>.') + 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