Skip to content

Commit d60655d

Browse files
committed
issue2551181 - allow issueXXX#fragment to generate a link with fragment
There is another ticket to add id's to elements displaying messages in issue.item.html. This change allows a fast way to link to such an element in a long issue with many messages once that other issue is committed and merged into a tracker template.
1 parent 7d3e4bd commit d60655d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ Features:
9696
Access-Control-Allow-Headers headers. (John Rouillard)
9797
- issue2550991 - define default cache control settings for javascript
9898
and css assets. (John Rouillard)
99+
- issue2551181 - fragments can be appended to designators. So
100+
issue23#msg24 could jump to the element with id msg24 in issue 23.
101+
Before this patch you would have two links issue23 and msg24
102+
separated by # (John Rouillard).
103+
99104

100105
2021-07-13 2.1.0
101106

roundup/cgi/templating.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ class StringHTMLProperty(HTMLProperty):
16121612
(/[\w\-$.+!*(),;:@&=?/~\\#%]*)? # path etc.
16131613
)|
16141614
(?P<email>[-+=%/\w\.]+@[\w\.\-]+)|
1615-
(?P<item>(?P<class>[A-Za-z_]+)(\s*)(?P<id>\d+))
1615+
(?P<item>(?P<class>[A-Za-z_]+)(\s*)(?P<id>\d+)(?P<fragment>\#[^][\#%^{}"<>\s]+)?)
16161616
)''', re.X | re.I)
16171617
protocol_re = re.compile('^(ht|f)tp(s?)://', re.I)
16181618

@@ -1630,7 +1630,7 @@ def _hyper_repl(self, match):
16301630
return self._hyper_repl_email(match, '<a href="mailto:%s">%s</a>')
16311631
elif len(match.group('id')) < 10:
16321632
return self._hyper_repl_item(match,
1633-
'<a href="%(cls)s%(id)s">%(item)s</a>')
1633+
'<a href="%(cls)s%(id)s%(fragment)s">%(item)s</a>')
16341634
else:
16351635
# just return the matched text
16361636
return match.group(0)
@@ -1664,6 +1664,9 @@ def _hyper_repl_item(self, match, replacement):
16641664
item = match.group('item')
16651665
cls = match.group('class').lower()
16661666
id = match.group('id')
1667+
fragment = match.group('fragment')
1668+
if fragment is None:
1669+
fragment=""
16671670
try:
16681671
# make sure cls is a valid tracker classname
16691672
cl = self._db.getclass(cls)

test/test_templating.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ def test_url_replace(self):
450450
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '')
451451
def t(s): return p.hyper_re.sub(p._hyper_repl, s)
452452
ae = self.assertEqual
453+
ae(t('issue5#msg10'), '<a href="issue5#msg10">issue5#msg10</a>')
454+
ae(t('issue5'), '<a href="issue5">issue5</a>')
455+
ae(t('issue2255'), 'issue2255')
453456
ae(t('foo https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4 bar'),
454457
'foo <a href="https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4" rel="nofollow noopener">'
455458
'https://example.com/demo/issue8#24MRV9BZYx:V:1B~sssssssssssssss~4~4</a> bar')

0 commit comments

Comments
 (0)