From 29eadf71414d583fc2162857cf08eab6bd23f1f4 Mon Sep 17 00:00:00 2001 From: Michal Siedlaczek Date: Sun, 11 Mar 2018 17:47:18 -0400 Subject: [PATCH] Filter installed dictionaries using a regex to ensure correct name --- qutebrowser/browser/webengine/spell.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/qutebrowser/browser/webengine/spell.py b/qutebrowser/browser/webengine/spell.py index beebe4da7..b887a2295 100644 --- a/qutebrowser/browser/webengine/spell.py +++ b/qutebrowser/browser/webengine/spell.py @@ -24,16 +24,14 @@ import os import re from PyQt5.QtCore import QLibraryInfo -from qutebrowser.utils import log +from qutebrowser.utils import log, message + +dict_version_re = re.compile(r".+-(?P[0-9]+-[0-9]+?)\.bdic") 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.fullmatch(filename) - if match is None: - raise ValueError('the given dictionary file name is malformed: {}' - .format(filename)) + match = dict_version_re.match(filename) return tuple(int(n) for n in match.group('version').split('-')) @@ -46,7 +44,7 @@ def dictionary_dir(): def local_files(code): """Return all installed dictionaries for the given code.""" pathname = os.path.join(dictionary_dir(), '{}*.bdic'.format(code)) - matching_dicts = glob.glob(pathname) + matching_dicts = filter(dict_version_re.match, glob.glob(pathname)) files = [] for matching_dict in sorted(matching_dicts, key=version, reverse=True): filename = os.path.basename(matching_dict)