Skip to content

Commit

Permalink
fix(secrets): fix find line (#6864)
Browse files Browse the repository at this point in the history
  • Loading branch information
omryMen authored Nov 21, 2024
1 parent aa86ecc commit cb1aaac
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions checkov/secrets/plugins/custom_regex_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ def _find_potential_secret(
continue
multiline_matches = multiline_regex.findall(file_content)
for mm in multiline_matches:
line_num = find_line_number(file_content, mm, line_number)
quoted_mm = f"'{mm}'"
ps = PotentialSecret(
type=regex_data["Name"],
filename=filename,
secret=quoted_mm,
line_number=find_line_number(file_content, mm, line_number),
line_number=line_num,
is_verified=is_verified,
is_added=is_added,
is_removed=is_removed,
Expand Down Expand Up @@ -219,9 +220,12 @@ def analyze_string(self, string: str, **kwargs: Optional[Dict[str, Any]]) -> Gen


def find_line_number(file_string: str, substring: str, default_line_number: int) -> int:
lines = file_string.splitlines()

for line_number, line in enumerate(lines, start=1):
if substring in line:
return line_number
return default_line_number
try:
lines = file_string.splitlines()

for line_number, line in enumerate(lines, start=1):
if substring in line:
return line_number
return default_line_number
except Exception:
return default_line_number

0 comments on commit cb1aaac

Please sign in to comment.