1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

fixing escape()

fixing escape() as replacing a None would throw an exception 'NoneType' object has no attribute 'replace'. useful in case of escaping a None string given from message.from_user.last_name as you dont know wether the user has a last name or not
This commit is contained in:
reddere 2022-12-03 13:33:22 +01:00 committed by GitHub
parent 109ae69f27
commit 34acae9a59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -399,8 +399,12 @@ def escape(text: str) -> str:
:return: the escaped text
"""
chars = {"&": "&amp;", "<": "&lt;", ">": "&gt;"}
for old, new in chars.items(): text = text.replace(old, new)
return text
if text == None:
return None
else:
for old, new in chars.items():
text = text.replace(old, new)
return text
def user_link(user: types.User, include_id: bool=False) -> str: