mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-08 17:13:56 +00:00
Fix empty match string in text filter
This commit is contained in:
parent
ab9264e2c9
commit
974f19a614
1 changed files with 6 additions and 6 deletions
|
|
@ -221,13 +221,13 @@ class Text(Filter):
|
||||||
:param ignore_case: case insensitive
|
:param ignore_case: case insensitive
|
||||||
"""
|
"""
|
||||||
# Only one mode can be used. check it.
|
# Only one mode can be used. check it.
|
||||||
check = sum(map(bool, (equals, contains, startswith, endswith)))
|
check = sum(map(lambda s: s is not None, (equals, contains, startswith, endswith)))
|
||||||
if check > 1:
|
if check > 1:
|
||||||
args = "' and '".join([arg[0] for arg in [('equals', equals),
|
args = "' and '".join([arg[0] for arg in [('equals', equals),
|
||||||
('contains', contains),
|
('contains', contains),
|
||||||
('startswith', startswith),
|
('startswith', startswith),
|
||||||
('endswith', endswith)
|
('endswith', endswith)
|
||||||
] if arg[1]])
|
] if arg[1] is not None])
|
||||||
raise ValueError(f"Arguments '{args}' cannot be used together.")
|
raise ValueError(f"Arguments '{args}' cannot be used together.")
|
||||||
elif check == 0:
|
elif check == 0:
|
||||||
raise ValueError(f"No one mode is specified!")
|
raise ValueError(f"No one mode is specified!")
|
||||||
|
|
@ -266,22 +266,22 @@ class Text(Filter):
|
||||||
if self.ignore_case:
|
if self.ignore_case:
|
||||||
text = text.lower()
|
text = text.lower()
|
||||||
|
|
||||||
if self.equals:
|
if self.equals is not None:
|
||||||
self.equals = str(self.equals)
|
self.equals = str(self.equals)
|
||||||
if self.ignore_case:
|
if self.ignore_case:
|
||||||
self.equals = self.equals.lower()
|
self.equals = self.equals.lower()
|
||||||
return text == self.equals
|
return text == self.equals
|
||||||
elif self.contains:
|
elif self.contains is not None:
|
||||||
self.contains = str(self.contains)
|
self.contains = str(self.contains)
|
||||||
if self.ignore_case:
|
if self.ignore_case:
|
||||||
self.contains = self.contains.lower()
|
self.contains = self.contains.lower()
|
||||||
return self.contains in text
|
return self.contains in text
|
||||||
elif self.startswith:
|
elif self.startswith is not None:
|
||||||
self.startswith = str(self.startswith)
|
self.startswith = str(self.startswith)
|
||||||
if self.ignore_case:
|
if self.ignore_case:
|
||||||
self.startswith = self.startswith.lower()
|
self.startswith = self.startswith.lower()
|
||||||
return text.startswith(self.startswith)
|
return text.startswith(self.startswith)
|
||||||
elif self.endswith:
|
elif self.endswith is not None:
|
||||||
self.endswith = str(self.endswith)
|
self.endswith = str(self.endswith)
|
||||||
if self.ignore_case:
|
if self.ignore_case:
|
||||||
self.endswith = self.endswith.lower()
|
self.endswith = self.endswith.lower()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue