Commit 127bb4c8 authored by Frédéric Mangano-Tarumi's avatar Frédéric Mangano-Tarumi Committed by Lukas Fleischer
Browse files

rendercomment: safer Flyspray task linkification

When an FS#123 is part of a code block, it must not be converted into a
link. FS#123 may also appear inside an URL, in which case regular
linkifaction of URLs must take precedence.

Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <>
parent 199f34e4
......@@ -29,18 +29,25 @@ class LinkifyExtension(markdown.extensions.Extension):
md.inlinePatterns.add('linkify', processor, '_end')
class FlysprayLinksPreprocessor(markdown.preprocessors.Preprocessor):
_fsre = re.compile(r'\b(FS#(\d+))\b')
_sub = r'[\1](\2)'
class FlysprayLinksInlineProcessor(markdown.inlinepatterns.InlineProcessor):
Turn Flyspray task references like FS#1234 into links to
The pattern's capture group 0 is the text of the link and group 1 is the
Flyspray task ID.
def run(self, lines):
return [self._fsre.sub(self._sub, line) for line in lines]
def handleMatch(self, m, data):
el = markdown.util.etree.Element('a')
el.set('href', f'{}')
el.text = markdown.util.AtomicString(
return el, m.start(0), m.end(0)
class FlysprayLinksExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
preprocessor = FlysprayLinksPreprocessor(md)
md.preprocessors.add('flyspray-links', preprocessor, '_end')
processor = FlysprayLinksInlineProcessor(r'\bFS#(\d+)\b',md)
md.inlinePatterns.add('flyspray-links', processor, '_end')
class GitCommitsInlineProcessor(markdown.inlinepatterns.InlineProcessor):
......@@ -103,4 +103,30 @@ test_expect_success 'Test Git commit linkification.' '
test_cmp actual expected
test_expect_success 'Test Flyspray issue linkification.' '
sqlite3 aur.db <<-EOD &&
INSERT INTO PackageComments (ID, PackageBaseID, Comments, RenderedComment) VALUES (6, 1, "
", "");
cat <<-EOD >expected &&
<p><a href="">FS#1234567</a>.
<em><a href="">FS#1234</a></em>
<a href=""></a></p>
sqlite3 aur.db <<-EOD >actual &&
SELECT RenderedComment FROM PackageComments WHERE ID = 6;
test_cmp actual expected
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment