From ab8750eedbeb7be2779a49ff2da7cf8c460d9596 Mon Sep 17 00:00:00 2001 From: glubsy Date: Thu, 17 Jun 2021 03:49:59 +0200 Subject: [PATCH] Fix partial regex match yielding false positive --- core/directories.py | 20 +++++++++++++------- core/gui/exclude_list_dialog.py | 2 +- qt/exclude_list_dialog.py | 3 +-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/directories.py b/core/directories.py index 7cd103fc..78883662 100644 --- a/core/directories.py +++ b/core/directories.py @@ -108,18 +108,24 @@ class Directories: found_files = [] # print(f"len of files: {len(files)} {files}") for f in files: - found = False + matched = False for expr in self._exclude_list.compiled_files: - if expr.match(f): - found = True + if expr.fullmatch(f): + logging.debug(f"{expr} matched {f}.") + matched = True break - if not found: + if not matched: + logging.debug(f"path {root + os.sep + f}") for expr in self._exclude_list.compiled_paths: - if expr.match(root + os.sep + f): - found = True + if expr.fullmatch(root + os.sep + f): + print(f"{expr} matched {root}{os.sep}{f}.") + matched = True break - if not found: + if not matched: + logging.debug(f"Not filtering: {f}.") found_files.append(fs.get_file(rootPath + f, fileclasses=fileclasses)) + else: + logging.debug(f"Filtering: {f}") found_files = [f for f in found_files if f is not None] # In some cases, directories can be considered as files by dupeGuru, which is # why we have this line below. In fact, there only one case: Bundle files under diff --git a/core/gui/exclude_list_dialog.py b/core/gui/exclude_list_dialog.py index b56ea7d2..82e219a2 100644 --- a/core/gui/exclude_list_dialog.py +++ b/core/gui/exclude_list_dialog.py @@ -56,7 +56,7 @@ class ExcludeListDialogCore: matched = False for row in self.exclude_list_table.rows: compiled_regex = self.exclude_list.get_compiled(row.regex) - if compiled_regex and compiled_regex.match(test_string): + if compiled_regex and compiled_regex.fullmatch(test_string): matched = True row.highlight = True else: diff --git a/qt/exclude_list_dialog.py b/qt/exclude_list_dialog.py index 855d6ac4..63be5a4e 100644 --- a/qt/exclude_list_dialog.py +++ b/qt/exclude_list_dialog.py @@ -129,8 +129,7 @@ class ExcludeListDialog(QDialog): except re.error: self.reset_input_style() return - match = compiled.match(input_text) - if match: + if compiled.fullmatch(input_text): self._input_styled = True self.inputLine.setStyleSheet("background-color: rgb(10, 200, 10);") else: