diff --git a/aiogram/utils/text_decorations.py b/aiogram/utils/text_decorations.py
index 4e01bc8b..ac5262c1 100644
--- a/aiogram/utils/text_decorations.py
+++ b/aiogram/utils/text_decorations.py
@@ -26,7 +26,10 @@ class TextDecoration(ABC):
:param text:
:return:
"""
- if entity.type in ("bold", "italic", "code", "underline", "strikethrough"):
+ if entity.type in {"bot_command", "url", "mention", "phone_number"}:
+ # This entities should not be changed
+ return text
+ if entity.type in {"bold", "italic", "code", "underline", "strikethrough"}:
return cast(str, getattr(self, entity.type)(value=text))
if entity.type == "pre":
return (
@@ -34,17 +37,14 @@ class TextDecoration(ABC):
if entity.language
else self.pre(value=text)
)
- elif entity.type == "text_mention":
+ if entity.type == "text_mention":
from aiogram.api.types import User
user = cast(User, entity.user)
return self.link(value=text, link=f"tg://user?id={user.id}")
- elif entity.type == "mention":
- return text
- elif entity.type == "text_link":
+ if entity.type == "text_link":
return self.link(value=text, link=cast(str, entity.url))
- elif entity.type == "url":
- return text
+
return self.quote(text)
def unparse(self, text: str, entities: Optional[List[MessageEntity]] = None) -> str:
diff --git a/tests/test_utils/test_text_decorations.py b/tests/test_utils/test_text_decorations.py
index 5501c08f..790d327c 100644
--- a/tests/test_utils/test_text_decorations.py
+++ b/tests/test_utils/test_text_decorations.py
@@ -184,15 +184,29 @@ class TestTextDecoration:
html_decoration,
"@username",
[
- MessageEntity(
- type="mention", offset=0, length=9, url=None, user=None, language=None
- ),
- MessageEntity(
- type="bold", offset=0, length=9, url=None, user=None, language=None
- ),
+ MessageEntity(type="mention", offset=0, length=9),
+ MessageEntity(type="bold", offset=0, length=9),
],
"@username",
],
+ [
+ html_decoration,
+ "/command",
+ [
+ MessageEntity(type="bot_command", offset=0, length=8),
+ MessageEntity(type="bold", offset=0, length=8),
+ ],
+ "/command",
+ ],
+ [
+ html_decoration,
+ "+1-212-555-0123",
+ [
+ MessageEntity(type="phone_number", offset=0, length=15),
+ MessageEntity(type="bold", offset=0, length=15),
+ ],
+ "+1-212-555-0123",
+ ],
[
html_decoration,
"test te👍🏿st test",