From c8be3da67a67963e5727a60d6744fe68f671e5f5 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 13 Aug 2023 16:57:47 +0300 Subject: [PATCH] Fixed nested hashtag, cashtag and email message entities not being parsed correctly when these entities are inside another entity. --- CHANGES/1259.bugfix.rst | 1 + aiogram/utils/text_decorations.py | 5 ++++- tests/test_utils/test_text_decorations.py | 27 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 CHANGES/1259.bugfix.rst diff --git a/CHANGES/1259.bugfix.rst b/CHANGES/1259.bugfix.rst new file mode 100644 index 00000000..e070549d --- /dev/null +++ b/CHANGES/1259.bugfix.rst @@ -0,0 +1 @@ +Fixed nested hashtag, cashtag and email message entities not being parsed correctly when these entities are inside another entity. diff --git a/aiogram/utils/text_decorations.py b/aiogram/utils/text_decorations.py index 97430a32..693e0583 100644 --- a/aiogram/utils/text_decorations.py +++ b/aiogram/utils/text_decorations.py @@ -43,8 +43,11 @@ class TextDecoration(ABC): MessageEntityType.URL, MessageEntityType.MENTION, MessageEntityType.PHONE_NUMBER, + MessageEntityType.HASHTAG, + MessageEntityType.CASHTAG, + MessageEntityType.EMAIL, }: - # This entities should not be changed + # These entities should not be changed return text if entity.type in { MessageEntityType.BOLD, diff --git a/tests/test_utils/test_text_decorations.py b/tests/test_utils/test_text_decorations.py index 056bd1cb..7cf12bc7 100644 --- a/tests/test_utils/test_text_decorations.py +++ b/tests/test_utils/test_text_decorations.py @@ -243,6 +243,33 @@ class TestTextDecoration: [MessageEntity(type="bold", offset=0, length=8, url=None, user=None)], "👋🏾 Hi!", ], + [ + html_decoration, + "#test", + [ + MessageEntity(type="hashtag", offset=0, length=5), + MessageEntity(type="bold", offset=0, length=5), + ], + "#test", + ], + [ + html_decoration, + "$TEST", + [ + MessageEntity(type="cashtag", offset=0, length=5), + MessageEntity(type="bold", offset=0, length=5), + ], + "$TEST", + ], + [ + html_decoration, + "test@example.com", + [ + MessageEntity(type="email", offset=0, length=16), + MessageEntity(type="bold", offset=0, length=16), + ], + "test@example.com", + ], ], ) def test_unparse(