From 7097c9c4c0b255ec1f10f3ea14fa2b9c47f6c706 Mon Sep 17 00:00:00 2001 From: noobpk Date: Fri, 19 Nov 2021 18:54:34 +0700 Subject: [PATCH] Update pattern and code check --- helpdesk/models.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/helpdesk/models.py b/helpdesk/models.py index d2dcaae2..31bed5df 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -56,9 +56,18 @@ def get_markdown(text): if not text: return "" - schemes = '|'.join(helpdesk_settings.ALLOWED_URL_SCHEMES) - pattern = fr'([\[\s\S\]]*?)\((?!({schemes})).*:(.+)\)' - text = re.sub(pattern, '\\1(\\3)', text, flags=re.IGNORECASE) + pattern = fr'([\[\s\S\]]*?)\(([\s\S]*?):([\[\s\S\]]*?)\)' + # Regex check + 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( markdown(