X Tutup
Skip to content

Commit aeca3ca

Browse files
committed
basic token validation
refs python-telegram-bot#134
1 parent 21fdaa4 commit aeca3ca

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

telegram/bot.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Bot(TelegramObject):
5252
def __init__(self,
5353
token,
5454
base_url=None):
55-
self.token = token
55+
self.token = self._valid_token(token)
5656

5757
if base_url is None:
5858
self.base_url = 'https://api.telegram.org/bot%s' % self.token
@@ -744,3 +744,11 @@ def to_dict(self):
744744
def __reduce__(self):
745745
return (self.__class__, (self.token,
746746
self.base_url.replace(self.token, '')))
747+
748+
@staticmethod
749+
def _valid_token(token):
750+
"""a very basic validation on token"""
751+
left, sep, _right = token.partition(':')
752+
if (sep is None) or (not left.isdigit()) or (len(left) < 3):
753+
raise TelegramError('Invalid token')
754+
return token

0 commit comments

Comments
 (0)
X Tutup