Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lower_path to check_exclude_file() for exclude exact file path #376

Merged
merged 4 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions credsweeper/file_handler/file_path_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/file_handler/test_file_path_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down