From 4a2d0685ff90d7325ba7c430753f45b74e408a7b Mon Sep 17 00:00:00 2001 From: Ilya Samartsev Date: Sun, 21 Jun 2020 20:25:32 +0300 Subject: [PATCH] fix more escaping issues --- 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 6efa5ed8..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..df0d4f8b --- /dev/null +++ b/tests/test_utils/test_markdown.py @@ -0,0 +1,11 @@ +import pytest + +from aiogram.utils import markdown + + +class Test_escape: + 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\\\."