forked from extern/django-helpdesk
Update pattern and code check
This commit is contained in:
parent
4a2ca815fd
commit
7097c9c4c0
@ -56,9 +56,18 @@ def get_markdown(text):
|
|||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
schemes = '|'.join(helpdesk_settings.ALLOWED_URL_SCHEMES)
|
pattern = fr'([\[\s\S\]]*?)\(([\s\S]*?):([\[\s\S\]]*?)\)'
|
||||||
pattern = fr'([\[\s\S\]]*?)\((?!({schemes})).*:(.+)\)'
|
# Regex check
|
||||||
text = re.sub(pattern, '\\1(\\3)', text, flags=re.IGNORECASE)
|
if re.match(pattern, text):
|
||||||
|
# get get value of group regex
|
||||||
|
scheme = re.search(pattern, text, re.IGNORECASE).group(2)
|
||||||
|
# scheme check
|
||||||
|
if scheme in helpdesk_settings.ALLOWED_URL_SCHEMES:
|
||||||
|
replacement = '\\1(\\2:\\3)'
|
||||||
|
else:
|
||||||
|
replacement = '\\1(\\3)'
|
||||||
|
|
||||||
|
text = re.sub(pattern, replacement, text, flags=re.IGNORECASE)
|
||||||
|
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
markdown(
|
markdown(
|
||||||
|
Loading…
Reference in New Issue
Block a user