Skip to content

Commit f1aea0c

Browse files
author
Richard Jones
committed
make URL detection a little smarter about brackets per issue2550657
(thanks Ezio Melotti)
1 parent 678226f commit f1aea0c

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ are given with the most recent entry first.
66
Fixed:
77
- A bunch of regressions were introduced in the last release making Roundup
88
no longer work in Python releases prior to 2.6
9+
- make URL detection a little smarter about brackets per issue2550657
10+
(thanks Ezio Melotti)
911

1012

1113
2010-07-01 1.4.14

doc/acknowledgements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Georges Martin,
8484
Gordon McMillan,
8585
John F Meinel Jr,
8686
Roland Meister,
87+
Ezio Melotti,
8788
Ulrik Mikaelsson,
8889
John Mitchell,
8990
Ramiro Morales,

roundup/cgi/templating.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,16 +1361,21 @@ def _hyper_repl(self, match):
13611361
u = s = match.group('url')
13621362
if not self.protocol_re.search(s):
13631363
u = 'http://' + s
1364-
# catch an escaped ">" at the end of the URL
13651364
if s.endswith('>'):
1365+
# catch an escaped ">" at the end of the URL
13661366
u = s = s[:-4]
13671367
e = '>'
1368+
elif s.count('(') != s.count(')'):
1369+
# don't include extraneous ')' in the link
1370+
pos = s.rfind(')')
1371+
e = s[pos:]
1372+
u = s = s[:pos]
13681373
else:
13691374
e = ''
1370-
return '<a href="%s">%s</a>%s'%(u, s, e)
1375+
return '<a href="%s">%s</a>%s' % (u, s, e)
13711376
elif match.group('email'):
13721377
s = match.group('email')
1373-
return '<a href="mailto:%s">%s</a>'%(s, s)
1378+
return '<a href="mailto:%s">%s</a>' % (s, s)
13741379
elif len(match.group('id')) < 10:
13751380
return self._hyper_repl_item(match,
13761381
'<a href="%(cls)s%(id)s">%(item)s</a>')

test/test_templating.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,24 @@ 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)
149149
ae = self.assertEquals
150-
ae(t('http://roundup.net/'), '<a href="http://roundup.net/">http://roundup.net/</a>')
151-
ae(t('&lt;HTTP://roundup.net/&gt;'), '&lt;<a href="HTTP://roundup.net/">HTTP://roundup.net/</a>&gt;')
152-
ae(t('&lt;www.roundup.net&gt;'), '&lt;<a href="http://www.roundup.net">www.roundup.net</a>&gt;')
153150
ae(t('item123123123123'), 'item123123123123')
151+
ae(t('http://roundup.net/'),
152+
'<a href="http://roundup.net/">http://roundup.net/</a>')
153+
ae(t('&lt;HTTP://roundup.net/&gt;'),
154+
'&lt;<a href="HTTP://roundup.net/">HTTP://roundup.net/</a>&gt;')
155+
ae(t('&lt;www.roundup.net&gt;'),
156+
'&lt;<a href="http://www.roundup.net">www.roundup.net</a>&gt;')
157+
ae(t('(www.roundup.net)'),
158+
'(<a href="http://www.roundup.net">www.roundup.net</a>)')
159+
ae(t('foo http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx bar'),
160+
'foo <a href="http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx">'
161+
'http://msdn.microsoft.com/en-us/library/ms741540(VS.85).aspx</a> bar')
162+
ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language))'),
163+
'(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)">'
164+
'http://en.wikipedia.org/wiki/Python_(programming_language)</a>)')
165+
ae(t('(e.g. http://en.wikipedia.org/wiki/Python_(programming_language)).'),
166+
'(e.g. <a href="http://en.wikipedia.org/wiki/Python_(programming_language)">'
167+
'http://en.wikipedia.org/wiki/Python_(programming_language)</a>).')
154168

155169
'''
156170
class HTMLPermissions:

0 commit comments

Comments
 (0)