From 34acae9a59e182059c973ee29e1faa57963ed1d2 Mon Sep 17 00:00:00 2001 From: reddere <111050360+reddere@users.noreply.github.com> Date: Sat, 3 Dec 2022 13:33:22 +0100 Subject: [PATCH 1/4] 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 --- telebot/util.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/telebot/util.py b/telebot/util.py index 485d8e6..5eee539 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -399,8 +399,12 @@ def escape(text: str) -> str: :return: the escaped text """ chars = {"&": "&", "<": "<", ">": ">"} - 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: From 669c18fdc01fbcbc19315f87275301045631064d Mon Sep 17 00:00:00 2001 From: reddere <111050360+reddere@users.noreply.github.com> Date: Sat, 3 Dec 2022 14:11:07 +0100 Subject: [PATCH 2/4] update updated "== None" to "is None" and adjusted the else statement --- telebot/util.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/telebot/util.py b/telebot/util.py index 5eee539..86528a8 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -399,11 +399,10 @@ def escape(text: str) -> str: :return: the escaped text """ chars = {"&": "&", "<": "<", ">": ">"} - if text == None: + if text is None: return None else: - for old, new in chars.items(): - text = text.replace(old, new) + for old, new in chars.items(): text = text.replace(old, new) return text From ae20cb9f315c0af45973ebf064c4d22f33c1b67f Mon Sep 17 00:00:00 2001 From: reddere <111050360+reddere@users.noreply.github.com> Date: Sat, 3 Dec 2022 14:21:31 +0100 Subject: [PATCH 3/4] Update util.py --- telebot/util.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/telebot/util.py b/telebot/util.py index 86528a8..cc0dae3 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -401,8 +401,7 @@ def escape(text: str) -> str: chars = {"&": "&", "<": "<", ">": ">"} if text is None: return None - else: - for old, new in chars.items(): text = text.replace(old, new) + for old, new in chars.items(): text = text.replace(old, new) return text From 4ed460b137685846f75de219f84440fb21200fe6 Mon Sep 17 00:00:00 2001 From: reddere <111050360+reddere@users.noreply.github.com> Date: Sat, 3 Dec 2022 14:23:10 +0100 Subject: [PATCH 4/4] Update util.py --- telebot/util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/telebot/util.py b/telebot/util.py index cc0dae3..e52ee83 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -401,8 +401,9 @@ def escape(text: str) -> str: chars = {"&": "&", "<": "<", ">": ">"} if text is None: return None - for old, new in chars.items(): text = text.replace(old, new) - return text + for old, new in chars.items(): + text = text.replace(old, new) + return text def user_link(user: types.User, include_id: bool=False) -> str: