Skip to content

Commit

Permalink
manifest file search now case-insensitive (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
flowstate authored Dec 19, 2024
1 parent f874edb commit 6d4fc56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = 'socket.dev'
__version__ = '1.0.37'
__version__ = '1.0.38'
38 changes: 24 additions & 14 deletions socketsecurity/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,15 @@ def match_supported_files(files: list) -> bool:
patterns = socket_globs[ecosystem]
for file_name in patterns:
pattern = patterns[file_name]["pattern"]
# path_pattern = f"**/{pattern}"
for file in files:
if "\\" in file:
file = file.replace("\\", "/")
if PurePath(file).match(pattern):
matched_files.append(file)
# Split path and filename
path_parts = PurePath(file).parts
if path_parts:
# Compare only the filename portion case-insensitively
if PurePath(path_parts[-1].lower()).match(pattern.lower()):
matched_files.append(file)
if len(matched_files) == 0:
not_matched = True
return not_matched
Expand All @@ -435,17 +438,24 @@ def find_files(path: str) -> list:
patterns = socket_globs[ecosystem]
for file_name in patterns:
pattern = patterns[file_name]["pattern"]
file_path = f"{path}/**/{pattern}"

log.debug(f"Globbing {file_path}")
glob_start = time.time()
glob_files = glob(file_path, recursive=True)
for glob_file in glob_files:
if glob_file not in files:
files.add(glob_file)
glob_end = time.time()
glob_total_time = glob_end - glob_start
log.debug(f"Glob for pattern {file_path} took {glob_total_time:.2f} seconds")
# Keep path as-is but try filename variations
file_paths = [
f"{path}/**/{pattern}",
f"{path}/**/{pattern.lower()}",
f"{path}/**/{pattern.upper()}",
f"{path}/**/{pattern.capitalize()}"
]

for file_path in file_paths:
log.debug(f"Globbing {file_path}")
glob_start = time.time()
glob_files = glob(file_path, recursive=True)
for glob_file in glob_files:
if glob_file not in files:
files.add(glob_file)
glob_end = time.time()
glob_total_time = glob_end - glob_start
log.debug(f"Glob for pattern {file_path} took {glob_total_time:.2f} seconds")

log.debug("Finished Find Files")
end_time = time.time()
Expand Down

0 comments on commit 6d4fc56

Please sign in to comment.