Skip to content

Commit

Permalink
Catch value error when performing audit hightlight line if the secret…
Browse files Browse the repository at this point in the history
… is not found on that line, instead of breaking the tool (Yelp#568)
  • Loading branch information
jpdakran committed Jun 23, 2022
1 parent 8996b7a commit b261af9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions detect_secrets/util/code_snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .color import AnsiColor
from .color import colorize
from detect_secrets.exceptions import SecretNotFoundOnSpecifiedLineError


def get_code_snippet(
Expand Down Expand Up @@ -71,16 +72,19 @@ def highlight_line(self, payload: str) -> 'CodeSnippet':
"""
:param payload: string to highlight, on chosen line
"""
index_of_payload = self.target_line.lower().index(payload.lower())
end_of_payload = index_of_payload + len(payload)

self.target_line = u'{}{}{}'.format(
self.target_line[:index_of_payload],
self.apply_highlight(self.target_line[index_of_payload:end_of_payload]),
self.target_line[end_of_payload:],
)
try:
index_of_payload = self.target_line.lower().index(payload.lower())
end_of_payload = index_of_payload + len(payload)

self.target_line = u'{}{}{}'.format(
self.target_line[:index_of_payload],
self.apply_highlight(self.target_line[index_of_payload:end_of_payload]),
self.target_line[end_of_payload:],
)

return self
return self
except ValueError:
raise SecretNotFoundOnSpecifiedLineError(self.target_index)

def get_line_number(self, line_number: int) -> str:
"""Broken out, for custom colorization."""
Expand Down

0 comments on commit b261af9

Please sign in to comment.