Skip to content

Commit 35886dd

Browse files
author
Richard Jones
committed
improve handling of '>' when URLs are converted to links
issue2550664 (thanks Ezio Melotti)
1 parent b02c5f3 commit 35886dd

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Fixed:
2222
- fix for incorrect except: syntax, issue2550661 (thanks Jakub Wilk)
2323
- No longer use the root logger, use a logger with prefix "roundup",
2424
see http://thread.gmane.org/gmane.comp.bug-tracking.roundup.devel/5356
25+
- improve handling of '>' when URLs are converted to links, issue2550664
26+
(thanks Ezio Melotti)
2527

2628

2729
2010-07-12 1.4.15

roundup/cgi/templating.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,18 +1361,18 @@ def _hyper_repl_url(self, match, replacement):
13611361
u = s = match.group('url')
13621362
if not self.protocol_re.search(s):
13631363
u = 'http://' + s
1364-
if s.endswith('>'):
1365-
# catch an escaped ">" at the end of the URL
1366-
u = s = s[:-4]
1367-
e = '>'
1368-
elif s.count('(') != s.count(')'):
1364+
end = ''
1365+
if '>' in s:
1366+
# catch an escaped ">" in the URL
1367+
pos = s.find('>')
1368+
end = s[pos:]
1369+
u = s = s[:pos]
1370+
if ')' in s and s.count('(') != s.count(')'):
13691371
# don't include extraneous ')' in the link
13701372
pos = s.rfind(')')
1371-
e = s[pos:]
1373+
end = s[pos:] + end
13721374
u = s = s[:pos]
1373-
else:
1374-
e = ''
1375-
return replacement % (u, s, e)
1375+
return replacement % (u, s, end)
13761376

13771377
def _hyper_repl_email(self, match, replacement):
13781378
s = match.group('email')

test/test_templating.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,14 @@ def t(s, nothing=False, **groups):
146146
def test_url_replace(self):
147147
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')
148148
def t(s): return p.hyper_re.sub(p._hyper_repl, s)
149-
ae = self.assertEquals
149+
ae = self.assertEqual
150150
ae(t('item123123123123'), 'item123123123123')
151151
ae(t('http://roundup.net/'),
152152
'<a href="http://roundup.net/">http://roundup.net/</a>')
153153
ae(t('&lt;HTTP://roundup.net/&gt;'),
154154
'&lt;<a href="HTTP://roundup.net/">HTTP://roundup.net/</a>&gt;')
155+
ae(t('&lt;http://roundup.net/&gt;.'),
156+
'&lt;<a href="http://roundup.net/">http://roundup.net/</a>&gt;.')
155157
ae(t('&lt;www.roundup.net&gt;'),
156158
'&lt;<a href="http://www.roundup.net">www.roundup.net</a>&gt;')
157159
ae(t('(www.roundup.net)'),
@@ -165,6 +167,12 @@ def t(s): return p.hyper_re.sub(p._hyper_repl, s)
165167
ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language)).'),
166168
'(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)">'
167169
'http://en.wikipedia.org/wiki/Python_(programming_language)</a>).')
170+
ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language))&gt;.'),
171+
'(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)">'
172+
'http://en.wikipedia.org/wiki/Python_(programming_language)</a>)&gt;.')
173+
ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language&gt;)).'),
174+
'(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language">'
175+
'http://en.wikipedia.org/wiki/Python_(programming_language</a>&gt;)).')
168176

169177
'''
170178
class HTMLPermissions:

0 commit comments

Comments
 (0)