Prevent unexpected timedelta matches (#5393)

* Prevent unexpected matches by asserting whitespace or eof at the end of matches

* Use a positive lookahead instead of a capturing group to support 1d6h syntax

* Use fullmatch instead of modifying regex strings
This commit is contained in:
Flame442 2021-12-29 18:46:36 -05:00 committed by GitHub
parent 9c05db1104
commit dce2378806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,7 +76,7 @@ def _parse_and_match(string_to_match: str, allowed_units: List[str]) -> Optional
"""
Local utility function to match TIME_RE string above to user input for both parse_timedelta and parse_relativedelta
"""
matches = TIME_RE.match(string_to_match)
matches = TIME_RE.fullmatch(string_to_match)
if matches:
params = {k: int(v) for k, v in matches.groupdict().items() if v is not None}
for k in params.keys():