rich text truelinks: Excape - in regex correctly

This commit is contained in:
Raphael Michel
2021-01-14 13:22:40 +01:00
parent 99f3360c44
commit 5375f6aec1
2 changed files with 5 additions and 1 deletions

View File

@@ -100,7 +100,7 @@ def truelink_callback(attrs, new=False):
<a href="https://maps.google.com/location/foo">https://maps.google.com</a>
"""
text = re.sub('[^a-zA-Z0-9.-/_]', '', attrs.get('_text')) # clean up link text
text = re.sub(r'[^a-zA-Z0-9.\-/_]', '', attrs.get('_text')) # clean up link text
href_url = urllib.parse.urlparse(attrs[None, 'href'])
if URL_RE.match(text) and href_url.scheme not in ('tel', 'mailto'):
# link text looks like a url

View File

@@ -17,6 +17,10 @@ from pretix.base.templatetags.rich_text import (
("mail@example.org",
'<a href="mailto:mail@example.org">mail@example.org</a>'),
# Test truelink_callback
('evilsite.com',
'<a href="http://evilsite.com" rel="noopener" target="_blank">evilsite.com</a>'),
('cool-example.eu',
'<a href="http://cool-example.eu" rel="noopener" target="_blank">cool-example.eu</a>'),
('<a href="https://evilsite.com">Evil Site</a>',
'<a href="https://evilsite.com" rel="noopener" target="_blank">Evil Site</a>'),
('<a href="https://evilsite.com">evilsite.com</a>',