diff options
| author | CapnS <[email protected]> | 2019-03-29 10:57:49 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-04-06 19:19:58 -0400 |
| commit | 24d3a5a48da5c99c83f9933937be9f3c5008d85a (patch) | |
| tree | ff5fe7a29364fe38579aa317db7b8dbf957ac59e | |
| parent | Add fetch custom emoji, all custom emojis; Add user property to Emoji (diff) | |
| download | discord.py-24d3a5a48da5c99c83f9933937be9f3c5008d85a.tar.xz discord.py-24d3a5a48da5c99c83f9933937be9f3c5008d85a.zip | |
Only escape characters as necessary in clean_content
Fixes #1885
| -rw-r--r-- | discord/ext/commands/converter.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 98d601fd..600f4be9 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -473,16 +473,11 @@ class clean_content(Converter): result = pattern.sub(repl, argument) if self.escape_markdown: - transformations = { - re.escape(c): '\\' + c - for c in ('*', '`', '_', '~', '\\', '||') - } - - def replace(obj): - return transformations.get(re.escape(obj.group(0)), '') - - pattern = re.compile('|'.join(transformations.keys())) - result = pattern.sub(replace, result) + result = re.sub(r'\\', r'\\\\', result) + for c in ('*', '`', '_', '~', '|'): + regex = r'\{0}(?=([\s\S]*((?<!\{0})\{0})))'.format(c) + replace = '\{0}'.format(c) + result = re.sub(regex, replace, result) # Completely ensure no mentions escape: return re.sub(r'@(everyone|here|[!&]?[0-9]{17,21})', '@\u200b\\1', result) |