Fix partial regex match yielding false positive

This commit is contained in:
glubsy 2021-06-17 03:49:59 +02:00
parent 0b46ca2222
commit ab8750eedb
3 changed files with 15 additions and 10 deletions

View File

@ -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

View File

@ -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:

View File

@ -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: