Skip to content

Commit 24b8cf9

Browse files
author
Richard Jones
committed
fix incorrect hyperlinking markup
1 parent 6ae023f commit 24b8cf9

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

44
2003-??-?? 0.6.0
5-
- better hyperlinking in web message texts
5+
- better hyperlinking in web message texts (handle ambiguous cases)
66
- support setting of properties on message and file through web and
77
email interface (thanks John Rouillard)
88
- allow additional control over the roundupdb email sending (explicit

roundup/cgi/templating.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -766,25 +766,26 @@ def __cmp__(self, other):
766766
return cmp(self._value, other)
767767

768768
class StringHTMLProperty(HTMLProperty):
769-
url_re = re.compile(r'\w{3,6}://\S+')
770-
email_re = re.compile(r'[\w\.]+@[\w\.\-]+')
771-
designator_re = re.compile(r'([a-z_]+)(\d+)')
772-
def _url_repl(self, match):
773-
s = match.group(0)
774-
return '<a href="%s">%s</a>'%(s, s)
775-
def _email_repl(self, match):
776-
s = match.group(0)
777-
return '<a href="mailto:%s">%s</a>'%(s, s)
778-
def _designator_repl(self, match):
779-
s = match.group(0)
780-
s1 = match.group(1)
781-
s2 = match.group(2)
782-
try:
783-
# make sure s1 is a valid tracker classname
784-
self._db.getclass(s1)
785-
return '<a href="%s">%s %s</a>'%(s, s1, s2)
786-
except KeyError:
787-
return '%s%s'%(s1, s2)
769+
hyper_re = re.compile(r'((?P<url>\w{3,6}://\S+)|'
770+
r'(?P<email>[\w\.]+@[\w\.\-]+)|'
771+
r'(?P<item>(?P<class>[a-z_]+)(?P<id>\d+)))')
772+
def _hyper_repl(self, match):
773+
if match.group('url'):
774+
s = match.group('url')
775+
return '<a href="%s">%s</a>'%(s, s)
776+
elif match.group('email'):
777+
s = match.group('email')
778+
return '<a href="mailto:%s">%s</a>'%(s, s)
779+
else:
780+
s = match.group('item')
781+
s1 = match.group('class')
782+
s2 = match.group('id')
783+
try:
784+
# make sure s1 is a valid tracker classname
785+
self._db.getclass(s1)
786+
return '<a href="%s">%s %s</a>'%(s, s1, s2)
787+
except KeyError:
788+
return '%s%s'%(s1, s2)
788789

789790
def plain(self, escape=0, hyperlink=0):
790791
''' Render a "plain" representation of the property
@@ -802,9 +803,7 @@ def plain(self, escape=0, hyperlink=0):
802803
if hyperlink:
803804
if not escape:
804805
s = cgi.escape(s)
805-
s = self.url_re.sub(self._url_repl, s)
806-
s = self.email_re.sub(self._email_repl, s)
807-
s = self.designator_re.sub(self._designator_repl, s)
806+
s = self.hyper_re.sub(self._hyper_repl, s)
808807
return s
809808

810809
def stext(self, escape=0):

0 commit comments

Comments
 (0)