diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 2f0fb5f98..668104665 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -1,5 +1,6 @@ import random import re +import regex from random import choice, choices from typing import List, Optional, Union @@ -193,3 +194,5 @@ def command_regex_matcher(match, upper=False): reason_regex = re.compile('(/(post|comment)/[0-9]+)', flags=re.A) discord_username_regex = re.compile("(\s|^|>).{2,32}#[0-9]{4}(?=[^0-9]|$)", flags=re.A) + +underscore_in_link_regex = regex.compile("(?<=https:\/\/[^\s)]+)_", flags=regex.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 5ea345ffc..d4cb38f50 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -291,7 +291,10 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys if FEATURES['MARKUP_COMMANDS']: sanitized = command_regex.sub(command_regex_matcher, sanitized) + sanitized = underscore_in_link_regex.sub(r'\_', sanitized) + sanitized = markdown(sanitized) + sanitized = strikethrough_regex.sub(r'\1\2', sanitized) # replacing zero width characters, overlines, fake colons diff --git a/migrations/20230127-fix-underscores-in-links.sh b/migrations/20230127-fix-underscores-in-links.sh new file mode 100644 index 000000000..ac1702550 --- /dev/null +++ b/migrations/20230127-fix-underscores-in-links.sh @@ -0,0 +1 @@ +pip3 install regex diff --git a/requirements.txt b/requirements.txt index db1851850..01949bc79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ pyotp pywebpush qrcode redis +regex requests SQLAlchemy tinycss2