From 2d1560e92afa67f13b48cc1699ac0e45d7cc1c22 Mon Sep 17 00:00:00 2001 From: Lorenz Steinert Date: Wed, 16 Oct 2019 16:08:01 +0200 Subject: [PATCH] fix start and end positions of match the `match.pos` and `match.endpos` are not the start and end of the matched group but the start and end arguments passed to the `re.match()` method. use `match.start()` and `match.end()` to find the beginning and the end of the matched group. see https://docs.python.org/3/library/re.html#match-objects --- maubot/handlers/command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maubot/handlers/command.py b/maubot/handlers/command.py index 165c366..93f1f90 100644 --- a/maubot/handlers/command.py +++ b/maubot/handlers/command.py @@ -284,8 +284,8 @@ def match(self, val: str, **kwargs) -> Tuple[str, Any]: val = val.split(" ")[0] match = self.regex.match(val) if match: - return (orig_val[:match.pos] + orig_val[match.endpos:], - match.groups() or val[match.pos:match.endpos]) + return (orig_val[:match.start()] + orig_val[match.end():], + match.groups() or val[match.start():match.end()]) return orig_val, None