M src/wiki/conf/settings.py => src/wiki/conf/settings.py +2 -0
@@ 103,6 103,8 @@ for tag in MARKDOWN_HTML_WHITELIST:
_default_attribute_whitelist[tag] = []
_default_attribute_whitelist[tag].append('class')
_default_attribute_whitelist[tag].append('id')
+ _default_attribute_whitelist[tag].append('target')
+ _default_attribute_whitelist[tag].append('rel')
_default_attribute_whitelist['img'].append('src')
_default_attribute_whitelist['img'].append('alt')
M src/wiki/plugins/links/mdx/urlize.py => src/wiki/plugins/links/mdx/urlize.py +2 -2
@@ 78,8 78,7 @@ URLIZE_RE = (
r'([A-F0-9]{1,4}:){1,6}:([A-F0-9]{1,4}){1,6}|' # IPv6, zeros in middle removed.
r'\[?([A-F0-9]{1,4}:){1,6}:\]?|' # IPv6, trailing zeros removed
r'\[?::\]?|' # IPv6, just "empty" address
- r'([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])?\.)+([A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # FQDN
- r'localhost' # localhost
+ r'([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])?\.)+([A-Z]{2,6}\.?|[A-Z]{2,}\.?)' # FQDN
r')' # end host identifier group
# Optional port
@@ 156,6 155,7 @@ class UrlizePattern(markdown.inlinepatterns.Pattern):
el = markdown.util.etree.Element("a")
el.set('href', url)
el.set('target', '_blank')
+ el.set('rel', 'nofollow')
el.append(icon)
el.append(span_text)
M tests/plugins/links/test_urlize.py => tests/plugins/links/test_urlize.py +17 -16
@@ 7,7 7,7 @@ from wiki.plugins.links.mdx.urlize import UrlizeExtension, makeExtension
# Template accepts two strings - href value and link text value.
EXPECTED_LINK_TEMPLATE = (
- '<a href="%s" target="_blank">'
+ '<a href="%s" rel="nofollow" target="_blank">'
'<span class="fa fa-external-link">'
'</span>'
'<span>'
@@ 102,16 102,9 @@ FIXTURE_POSITIVE_MATCHES = [
'my.long.domain.example.com',
EXPECTED_PARAGRAPH_TEMPLATE % ('http://my.long.domain.example.com', 'my.long.domain.example.com')
),
- (
- 'localhost',
- EXPECTED_PARAGRAPH_TEMPLATE % ('http://localhost', 'localhost')
- ),
# Test port section.
- (
- 'localhost:8000',
- EXPECTED_PARAGRAPH_TEMPLATE % ('http://localhost:8000', 'localhost:8000')
- ),
+
(
'10.1.1.1:8000',
EXPECTED_PARAGRAPH_TEMPLATE % ('http://10.1.1.1:8000', '10.1.1.1:8000')
@@ 152,6 145,21 @@ FIXTURE_POSITIVE_MATCHES = [
FIXTURE_NEGATIVE_MATCHES = [
+ # localhost as part of another word.
+ (
+ 'localhosts',
+ '<p>localhosts</p>'
+ ),
+ (
+ 'localhost',
+ '<p>localhost</p>'
+
+ ),
+ (
+ 'localhost:8000',
+ '<p>localhost:8000</p>'
+ ),
+
# Incomplete FQDNs.
(
'example.',
@@ 161,13 169,6 @@ FIXTURE_NEGATIVE_MATCHES = [
'.example .com',
'<p>.example .com</p>'
),
-
- # localhost as part of another word.
- (
- 'localhosts',
- '<p>localhosts</p>'
- ),
-
# Invalid FQDNs.
(
'example-.com',