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 <jroot.junior@gmail.com>
This commit is contained in:
Alexey Berezin 2024-05-30 20:58:51 +03:00 committed by GitHub
parent b5d94f17b5
commit f50e058725
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 2 deletions

1
CHANGES/1496.bugfix.rst Normal file
View file

@ -0,0 +1 @@
Fixed wrong :code:`MarkdownV2` custom emoji parsing in :code:`aiogram.utils.text_decorations`

View file

@ -253,7 +253,7 @@ class MarkdownDecoration(TextDecoration):
return re.sub(pattern=self.MARKDOWN_QUOTE_PATTERN, repl=r"\\\1", string=value) return re.sub(pattern=self.MARKDOWN_QUOTE_PATTERN, repl=r"\\\1", string=value)
def custom_emoji(self, value: str, custom_emoji_id: str) -> str: 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: def blockquote(self, value: str) -> str:
return "\n".join(f">{line}" for line in value.splitlines()) return "\n".join(f">{line}" for line in value.splitlines())

View file

@ -99,7 +99,7 @@ class TestTextDecoration:
[ [
markdown_decoration, markdown_decoration,
MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"), MessageEntity(type="custom_emoji", offset=0, length=5, custom_emoji_id="42"),
"[test](tg://emoji?id=42)", "![test](tg://emoji?id=42)",
], ],
[ [
markdown_decoration, markdown_decoration,