Skip to content

Commit 85da0c6

Browse files
committed
Fixed the logic for case insensitive to not do multiple globs but still keep the correct path names
1 parent 6d4fc56 commit 85da0c6

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

socketsecurity/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '1.0.38'
2+
__version__ = '1.0.40'

socketsecurity/core/__init__.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -437,25 +437,17 @@ def find_files(path: str) -> list:
437437
for ecosystem in socket_globs:
438438
patterns = socket_globs[ecosystem]
439439
for file_name in patterns:
440-
pattern = patterns[file_name]["pattern"]
441-
# Keep path as-is but try filename variations
442-
file_paths = [
443-
f"{path}/**/{pattern}",
444-
f"{path}/**/{pattern.lower()}",
445-
f"{path}/**/{pattern.upper()}",
446-
f"{path}/**/{pattern.capitalize()}"
447-
]
448-
449-
for file_path in file_paths:
450-
log.debug(f"Globbing {file_path}")
451-
glob_start = time.time()
452-
glob_files = glob(file_path, recursive=True)
453-
for glob_file in glob_files:
454-
if glob_file not in files:
455-
files.add(glob_file)
456-
glob_end = time.time()
457-
glob_total_time = glob_end - glob_start
458-
log.debug(f"Glob for pattern {file_path} took {glob_total_time:.2f} seconds")
440+
pattern = Core.to_case_insensitive_regex(patterns[file_name]["pattern"])
441+
file_path = f"{path}/**/{pattern}"
442+
log.debug(f"Globbing {file_path}")
443+
glob_start = time.time()
444+
glob_files = glob(file_path, recursive=True)
445+
for glob_file in glob_files:
446+
if glob_file not in files:
447+
files.add(glob_file)
448+
glob_end = time.time()
449+
glob_total_time = glob_end - glob_start
450+
log.debug(f"Glob for pattern {file_path} took {glob_total_time:.2f} seconds")
459451

460452
log.debug("Finished Find Files")
461453
end_time = time.time()
@@ -872,6 +864,16 @@ def save_file(file_name: str, content: str) -> None:
872864
file.write(content)
873865
file.close()
874866

867+
@staticmethod
868+
def to_case_insensitive_regex(input_string: str) -> str:
869+
"""
870+
Converts a string into a case-insensitive regex format.
871+
Example: "pipfile" -> "[Pp][Ii][Pp][Ff][Ii][Ll][Ee]"
872+
:param input_string: The input string to convert.
873+
:return: A case-insensitive regex string.
874+
"""
875+
return ''.join(f'[{char.lower()}{char.upper()}]' if char.isalpha() else char for char in input_string)
876+
875877
# @staticmethod
876878
# def create_license_file(diff: Diff) -> None:
877879
# output = []

0 commit comments

Comments
 (0)