From f50e0587255f7ad1c75b2a69c43b207ea933815a Mon Sep 17 00:00:00 2001 From: Alexey Berezin <101830798+berezzin@users.noreply.github.com> Date: Thu, 30 May 2024 20:58:51 +0300 Subject: [PATCH] Fixed bug with wrong MarkdownV2 custom emoji parsing (#1497) * fixed bug with wrong markdownv2 custom emoji parsing * added changelog of 1496 issue * Update CHANGES/1496.bugfix.rst --------- Co-authored-by: Alex Root Junior --- CHANGES/1496.bugfix.rst | 1 + aiogram/utils/text_decorations.py | 2 +- tests/test_utils/test_text_decorations.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 CHANGES/1496.bugfix.rst diff --git a/CHANGES/1496.bugfix.rst b/CHANGES/1496.bugfix.rst new file mode 100644 index 00000000..02d44dbf --- /dev/null +++ b/CHANGES/1496.bugfix.rst @@ -0,0 +1 @@ +Fixed wrong :code:`MarkdownV2` custom emoji parsing in :code:`aiogram.utils.text_decorations` diff --git a/aiogram/utils/text_decorations.py b/aiogram/utils/text_decorations.py index 58d6c0f4..ae6227d3 100644 --- a/aiogram/utils/text_decorations.py +++ b/aiogram/utils/text_decorations.py @@ -253,7 +253,7 @@ class MarkdownDecoration(TextDecoration): return re.sub(pattern=self.MARKDOWN_QUOTE_PATTERN, repl=r"\\\1", string=value) def custom_emoji(self, value: str, custom_emoji_id: str) -> str: - return self.link(value=value, link=f"tg://emoji?id={custom_emoji_id}") + return f'!{self.link(value=value, link=f"tg://emoji?id={custom_emoji_id}")}' def blockquote(self, value: str) -> str: return "\n".join(f">{line}" for line in value.splitlines()) diff --git a/tests/test_utils/test_text_decorations.py b/tests/test_utils/test_text_decorations.py index 6a177ab3..2696f078 100644 --- a/tests/test_utils/test_text_decorations.py +++ b/tests/test_utils/test_text_decorations.py @@ -99,7 +99,7 @@ class TestTextDecoration: [ markdown_decoration, MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"), - "[test](tg://emoji?id=42)", + "![test](tg://emoji?id=42)", ], [ markdown_decoration,