From f9c367548fbeac1fc1a487abfa13fb59b25aefec Mon Sep 17 00:00:00 2001 From: unintended Date: Sat, 27 Jun 2020 16:17:38 +0300 Subject: [PATCH] Fix markdown escaping issues (#363) * #360 - Fix: escape '=' sign in markdown * fix more escaping issues * Rename test suite Co-authored-by: Alex Root Junior --- aiogram/utils/text_decorations.py | 2 +- tests/test_utils/test_markdown.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/test_utils/test_markdown.py diff --git a/aiogram/utils/text_decorations.py b/aiogram/utils/text_decorations.py index 77dc0ff3..3d22f637 100644 --- a/aiogram/utils/text_decorations.py +++ b/aiogram/utils/text_decorations.py @@ -163,7 +163,7 @@ class HtmlDecoration(TextDecoration): class MarkdownDecoration(TextDecoration): - MARKDOWN_QUOTE_PATTERN: Pattern[str] = re.compile(r"([_*\[\]()~`>#+\-|{}.!])") + MARKDOWN_QUOTE_PATTERN: Pattern[str] = re.compile(r"([_*\[\]()~`>#+\-=|{}.!\\])") def link(self, value: str, link: str) -> str: return f"[{value}]({link})" diff --git a/tests/test_utils/test_markdown.py b/tests/test_utils/test_markdown.py new file mode 100644 index 00000000..02faea2a --- /dev/null +++ b/tests/test_utils/test_markdown.py @@ -0,0 +1,11 @@ +import pytest + +from aiogram.utils import markdown + + +class TestMarkdownEscape: + def test_equality_sign_is_escaped(self): + assert markdown.escape_md(r"e = mc2") == r"e \= mc2" + + def test_pre_escaped(self): + assert markdown.escape_md(r"hello\.") == r"hello\\\."