diff options
author | Marco Zatta <marco@zatta.me> | 2020-12-08 19:49:37 +0100 |
---|---|---|
committer | Marco Zatta <marco@zatta.me> | 2020-12-08 19:56:44 +0100 |
commit | 5f93c1a68a9e7db8535998968214757e46b677af (patch) | |
tree | a3242ecc0be1c1ab9fe48854b89c3c497e6e544e /qutebrowser/utils/utils.py | |
parent | cc360cd4a34a126274c7b51f3b63afbaf3e05a02 (diff) | |
download | qutebrowser-5f93c1a68a9e7db8535998968214757e46b677af.tar.gz qutebrowser-5f93c1a68a9e7db8535998968214757e46b677af.zip |
Added tests and modifed regex to full match
Diffstat (limited to 'qutebrowser/utils/utils.py')
-rw-r--r-- | qutebrowser/utils/utils.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 60e8b5174..a991b2503 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -781,18 +781,17 @@ def parse_duration(duration: str) -> int: # For backward compatibility return milliseconds return int(duration) - match = re.search( - r'^(?P<hours>[0-9]+(\.[0-9])*h)?\s*' - r'(?P<minutes>[0-9]+(\.[0-9])*m)?\s*' - r'(?P<seconds>[0-9]+(\.[0-9])*s)?$', + match = re.fullmatch( + r'(?P<hours>[0-9]+(\.[0-9])?h)?\s*' + r'(?P<minutes>[0-9]+(\.[0-9])?m)?\s*' + r'(?P<seconds>[0-9]+(\.[0-9])?s)?', duration ) - if not match: + if not match or not match.group(0): raise ValueError( f"Invalid duration: {duration} - " "expected XhYmZs or a number of milliseconds" ) - seconds_string = match.group('seconds') if match.group('seconds') else '0' seconds = float(seconds_string.rstrip('s')) minutes_string = match.group('minutes') if match.group('minutes') else '0' |