diff options
| author | NCPlayz <[email protected]> | 2020-06-17 16:31:48 +0100 |
|---|---|---|
| committer | NCPlayz <[email protected]> | 2020-06-17 16:31:48 +0100 |
| commit | a2148d6d1a54fcff4edf49804e16c0b5831632b5 (patch) | |
| tree | b8ba7b60283b75be7ceb9364c2a1aeb23675c41b | |
| parent | Fix TypeError on missing shard_id kwarg (diff) | |
| download | discord.py-a2148d6d1a54fcff4edf49804e16c0b5831632b5.tar.xz discord.py-a2148d6d1a54fcff4edf49804e16c0b5831632b5.zip | |
Escape masked URLs; Support quotes for as_needed
| -rw-r--r-- | discord/utils.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/discord/utils.py b/discord/utils.py index e32ee7fd..510096dd 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -440,7 +440,9 @@ def resolve_invite(invite): _MARKDOWN_ESCAPE_SUBREGEX = '|'.join(r'\{0}(?=([\s\S]*((?<!\{0})\{0})))'.format(c) for c in ('*', '`', '_', '~', '|')) -_MARKDOWN_ESCAPE_REGEX = re.compile(r'(?P<markdown>%s)' % _MARKDOWN_ESCAPE_SUBREGEX) +_MARKDOWN_ESCAPE_COMMON = r'^>(?:>>)?\s|\[.+\]\(.+\)' + +_MARKDOWN_ESCAPE_REGEX = re.compile(r'(?P<markdown>%s|%s)' % (_MARKDOWN_ESCAPE_SUBREGEX, _MARKDOWN_ESCAPE_COMMON)) def escape_markdown(text, *, as_needed=False, ignore_links=True): r"""A helper function that escapes Discord's markdown. @@ -476,7 +478,7 @@ def escape_markdown(text, *, as_needed=False, ignore_links=True): return is_url return '\\' + groupdict['markdown'] - regex = r'(?P<markdown>[_\\~|\*`]|>(?:>>)?\s)' + regex = r'(?P<markdown>[_\\~|\*`]|%s)' % _MARKDOWN_ESCAPE_COMMON if ignore_links: regex = '(?:%s|%s)' % (url_regex, regex) return re.sub(regex, replacement, text) |