From 45f16fddadb068fafc614036433cdc1ad7ceadca Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon
Date: Mar 17 2017 09:10:48 +0000
Subject: Support irc:// links in our markdown and adjust the regex
In this commit we are improving our markdown processor in different
aspects:
- Replace the regex to match links with the one coming from the markdown
project itself, adjusted for our needs.
- Add support to link on irc:// and ircs:// in markdown, this is however
only partly working because the rendered markdown is passed onto
python-bleach which cleans the ircs links since ircs isn't in the list
of its supported protocols. More recent version of python-bleach (from
1.5 basically) would allow us to expand the list of supported protocols
and add ircs to it, but the version we are currently using (1.4.3) does
not offer that option.
Fixes https://pagure.io/pagure/issue/2085
---
diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py
index cb05477..57062b4 100644
--- a/pagure/pfmarkdown.py
+++ b/pagure/pfmarkdown.py
@@ -282,8 +282,10 @@ class PagureExtension(markdown.extensions.Extension):
def extendMarkdown(self, md, md_globals):
# First, make it so that bare links get automatically linkified.
markdown.inlinepatterns.AUTOLINK_RE = '(%s)' % '|'.join([
- r'<(?:f|ht)tps?://[^>]*>',
- r'\b(?:f|ht)tps?://[^)<>\s]+[^.,)<>\s]',
+ r'<((?:[Ff]|[Hh][Tt])[Tt][Pp][Ss]?://[^>]*)>',
+ r'\b(?:[Ff]|[Hh][Tt])[Tt][Pp][Ss]?://[^)<>\s]+[^.,)<>\s]',
+ r'<(Ii][Rr][Cc][Ss]?://[^>]*)>',
+ r'\b[Ii][Rr][Cc][Ss]?://[^)<>\s]+[^.,)<>\s]',
])
md.inlinePatterns['mention'] = MentionPattern(MENTION_RE)
diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py
index 0697f5b..266f329 100644
--- a/tests/test_pagure_lib.py
+++ b/tests/test_pagure_lib.py
@@ -3345,6 +3345,10 @@ class PagureLibtests(tests.Modeltests):
'pingou opened the PR forks/pingou/test#2',
'fork/pingou/ns/test#8 is private',
'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd',
+ 'irc://pagure.io',
+ 'ircs://pagure.io',
+ 'http://pagure.io',
+ 'https://pagure.io',
]
expected = [
# 'foo bar test#1 see?',
@@ -3383,7 +3387,18 @@ class PagureLibtests(tests.Modeltests):
'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd
'
+ '>test#9364354a4555ba17aa60f0dc844d70b74eb1aecd
',
+ # 'irc://pagure.io'
+ 'irc://pagure.io
',
+ # 'ircs://pagure.io' - This is getting cleaned by python-bleach
+ # and the version 1.4.3 that we have won't let us adjust the
+ # list of supported protocols
+ # 'ircs://pagure.io
',
+ 'irc://pagure.io
',
+ # 'http://pagure.io'
+ 'http://pagure.io
',
+ # 'https://pagure.io'
+ 'https://pagure.io
',
]
with pagure.APP.app_context():