Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ telegram.jpg

# virtual env
venv*
pyvenv.cfg
Scripts/

# environment manager:
.mise.toml
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `Kirill Vasin <https://github.com/vasinkd>`_
- `Kjwon15 <https://github.com/kjwon15>`_
- `Li-aung Yip <https://github.com/LiaungYip>`_
- `locobott <https://github.com/locobott>`_
- `Loo Zheng Yuan <https://github.com/loozhengyuan>`_
- `LRezende <https://github.com/lrezende>`_
- `Luca Bellanti <https://github.com/Trifase>`_
Expand Down
5 changes: 5 additions & 0 deletions changes/unreleased/4817.ZHx38jvj9zKRNZfQh9Xrpb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bugfixes = "Allow for pattern matching empty inline queries"
[[pull_requests]]
uid = "4817"
author_uid = "locobott"
closes_threads = []
6 changes: 1 addition & 5 deletions src/telegram/ext/_handlers/inlinequeryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ def check_update(self, update: object) -> Optional[Union[bool, Match[str]]]:
update.inline_query.chat_type not in self.chat_types
):
return False
if (
self.pattern
and update.inline_query.query
and (match := re.match(self.pattern, update.inline_query.query))
):
if self.pattern and (match := re.match(self.pattern, update.inline_query.query)):
return match
if not self.pattern:
return True
Expand Down
22 changes: 22 additions & 0 deletions tests/ext/test_inlinequeryhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ async def test_context_pattern(self, app, inline_query):
update.inline_query.query = "not_a_match"
assert not handler.check_update(update)

@pytest.mark.parametrize(
("query", "expected_result"),
[
pytest.param("", True, id="empty string"),
pytest.param("not empty", False, id="non_empty_string"),
],
)
async def test_empty_inline_query_pattern(self, app, query, expected_result):
handler = InlineQueryHandler(self.callback, pattern=r"^$")
app.add_handler(handler)

update = Update(
update_id=0,
inline_query=InlineQuery(
id="id", from_user=User(1, "test", False), query=query, offset=""
),
)

async with app:
await app.process_update(update)
assert self.test_flag == expected_result

@pytest.mark.parametrize("chat_types", [[Chat.SENDER], [Chat.SENDER, Chat.SUPERGROUP], []])
@pytest.mark.parametrize(
("chat_type", "result"), [(Chat.SENDER, True), (Chat.CHANNEL, False), (None, False)]
Expand Down
Loading