diff --git a/credsweeper/file_handler/file_path_extractor.py b/credsweeper/file_handler/file_path_extractor.py index a1a598636..84fa1213c 100644 --- a/credsweeper/file_handler/file_path_extractor.py +++ b/credsweeper/file_handler/file_path_extractor.py @@ -127,16 +127,18 @@ def check_exclude_file(config: Config, path: str) -> bool: Return: True when the file full path should be excluded according config """ - path = path.replace('\\', '/').lower() - if config.not_allowed_path_pattern.match(path): + path = path.replace('\\', '/') + lower_path = path.lower() + if config.not_allowed_path_pattern.match(lower_path): return True for exclude_pattern in config.exclude_patterns: - if exclude_pattern.match(path): + if exclude_pattern.match(lower_path): return True for exclude_path in config.exclude_paths: + # must be case-sensitive if exclude_path in path: return True - file_extension = Util.get_extension(path, lower=False) + file_extension = Util.get_extension(lower_path, lower=False) if file_extension in config.exclude_extensions: return True if not config.depth and file_extension in config.exclude_containers: diff --git a/tests/file_handler/test_file_path_extractor.py b/tests/file_handler/test_file_path_extractor.py index 212b22bb7..16fb5236c 100644 --- a/tests/file_handler/test_file_path_extractor.py +++ b/tests/file_handler/test_file_path_extractor.py @@ -46,6 +46,7 @@ def test_apply_gitignore_n(self) -> None: @pytest.mark.parametrize("file_path", [ "/tmp/test/dummy.p12", "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmptjz2p1zk\\test\\dummy.p12", + "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmptjz2p1zk\\TarGet\\dummy.p12", ]) def test_check_exclude_file_p(self, config: Config, file_path: pytest.fixture) -> None: config.find_by_ext = True @@ -55,7 +56,6 @@ def test_check_exclude_file_p(self, config: Config, file_path: pytest.fixture) - "dummy.JPG", "/tmp/target/dummy.p12", "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmptjz2p1zk\\target\\dummy.p12", - "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmptjz2p1zk\\tArGet\\dummy.p12", ]) def test_check_exclude_file_n(self, config: Config, file_path: pytest.fixture) -> None: config.find_by_ext = True