mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Rich text: Do not call link text heuristic for mailto:
This commit is contained in:
@@ -101,7 +101,8 @@ def truelink_callback(attrs, new=False):
|
|||||||
<a href="https://maps.google.com/location/foo">https://maps.google.com</a>
|
<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('[^a-zA-Z0-9.-/_]', '', attrs.get('_text')) # clean up link text
|
||||||
if URL_RE.match(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
|
# link text looks like a url
|
||||||
if text.startswith('//'):
|
if text.startswith('//'):
|
||||||
text = 'https:' + text
|
text = 'https:' + text
|
||||||
@@ -109,7 +110,6 @@ def truelink_callback(attrs, new=False):
|
|||||||
text = 'https://' + text
|
text = 'https://' + text
|
||||||
|
|
||||||
text_url = urllib.parse.urlparse(text)
|
text_url = urllib.parse.urlparse(text)
|
||||||
href_url = urllib.parse.urlparse(attrs[None, 'href'])
|
|
||||||
if text_url.netloc != href_url.netloc or not href_url.path.startswith(href_url.path):
|
if text_url.netloc != href_url.netloc or not href_url.path.startswith(href_url.path):
|
||||||
# link text contains an URL that has a different base than the actual URL
|
# link text contains an URL that has a different base than the actual URL
|
||||||
attrs['_text'] = attrs[None, 'href']
|
attrs['_text'] = attrs[None, 'href']
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from pretix.base.templatetags.rich_text import (
|
|||||||
("[Foo](/foo)",
|
("[Foo](/foo)",
|
||||||
'<a href="http://example.com/foo" rel="noopener" target="_blank">Foo</a>'),
|
'<a href="http://example.com/foo" rel="noopener" target="_blank">Foo</a>'),
|
||||||
("mail@example.org",
|
("mail@example.org",
|
||||||
'<a href="mailto:mail@example.org">mailto:mail@example.org</a>'),
|
'<a href="mailto:mail@example.org">mail@example.org</a>'),
|
||||||
# Test truelink_callback
|
# Test truelink_callback
|
||||||
('<a href="https://evilsite.com">Evil Site</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" rel="noopener" target="_blank">Evil Site</a>'),
|
||||||
|
|||||||
Reference in New Issue
Block a user