From 747a9bc5b6dfc566c02e4616e5a3002dbe42a95f Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Mon, 11 Dec 2017 21:32:55 +0000 Subject: [PATCH 1/5] Modify usage of re.match to fit re.fullmatch or re.search. re.match features an implicit left anchor, which can be surprising. re.fullmatch features implicit anchors on both sides, but is aptly named and unsurprising. re.search has no such implicit anchors, which ought to be the default even if a single anchor is needed. --- qutebrowser/browser/downloads.py | 2 +- qutebrowser/browser/webengine/spell.py | 2 +- qutebrowser/config/configtypes.py | 10 +++++----- qutebrowser/keyinput/basekeyparser.py | 3 ++- qutebrowser/misc/crashdialog.py | 2 +- qutebrowser/misc/keyhintwidget.py | 2 +- qutebrowser/utils/debug.py | 2 +- qutebrowser/utils/docutils.py | 2 +- qutebrowser/utils/urlutils.py | 4 ++-- qutebrowser/utils/utils.py | 2 +- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 5a2daae7e..dc0d83cbc 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -180,7 +180,7 @@ def transform_path(path): path = utils.expand_windows_drive(path) # Drive dependent working directories are not supported, e.g. # E:filename is invalid - if re.match(r'[A-Z]:[^\\]', path, re.IGNORECASE): + if re.fullmatch(r'[A-Z]:[^\\]', path, re.IGNORECASE): return None # Paths like COM1, ... # See https://github.com/qutebrowser/qutebrowser/issues/82 diff --git a/qutebrowser/browser/webengine/spell.py b/qutebrowser/browser/webengine/spell.py index ee2fb7813..9166180d4 100644 --- a/qutebrowser/browser/webengine/spell.py +++ b/qutebrowser/browser/webengine/spell.py @@ -30,7 +30,7 @@ from qutebrowser.utils import log def version(filename): """Extract the version number from the dictionary file name.""" version_re = re.compile(r".+-(?P[0-9]+-[0-9]+?)\.bdic") - match = version_re.match(filename) + match = version_re.fullmatch(filename) if match is None: raise ValueError('the given dictionary file name is malformed: {}' .format(filename)) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 8d0af173b..320798f6b 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -963,7 +963,7 @@ class Font(BaseType): # Gets set when the config is initialized. monospace_fonts = None font_regex = re.compile(r""" - ^( + ( ( # style (?P