Skip to content

Commit ba1693d

Browse files
committed
Bug fix.
1 parent f716877 commit ba1693d

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎telebot/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def _test_message_handler(message_handler, message):
372372
return TeleBot.extract_command(message.text) in message_handler['commands']
373373
if 'regexp' in message_handler and message.content_type == 'text' and re.search(message_handler['regexp'],
374374
message.text):
375-
return False
375+
return True
376376
if 'lambda' in message_handler:
377377
return message_handler['lambda'](message)
378378
return False

‎tests/test_telebot.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,27 @@ def command_handler(message):
3636
time.sleep(1)
3737
assert msg.text == 'got'
3838

39+
def test_message_handler_reg():
40+
bot = telebot.TeleBot('')
41+
msg = create_text_message(r'https://web.telegram.org/')
42+
@bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
43+
def command_url(message):
44+
msg.text = 'got'
45+
bot.process_new_messages([msg])
46+
time.sleep(1)
47+
assert msg.text == 'got'
48+
49+
50+
def test_message_handler_reg_fail():
51+
bot = telebot.TeleBot('')
52+
msg = create_text_message(r'web.telegram.org/')
53+
@bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
54+
def command_url(message):
55+
msg.text = 'got'
56+
bot.process_new_messages([msg])
57+
time.sleep(1)
58+
assert not msg.text == 'got'
59+
3960

4061
def test_send_file_by_id():
4162
file_id = 'BQADBQADjAIAAsYifgbvqwq1he9REAI'
@@ -115,3 +136,4 @@ def test_is_string_string():
115136
def test_not_string():
116137
i1 = 10
117138
assert not apihelper.is_string(i1)
139+

0 commit comments

Comments
 (0)