Skip to content

Commit

Permalink
fix start and end positions of match
Browse files Browse the repository at this point in the history
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
  • Loading branch information
L0ric0 committed Oct 16, 2019
1 parent bf4c062 commit 2d1560e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions maubot/handlers/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 2d1560e

Please sign in to comment.