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

#467: Catch ValueError - Audit #568

Merged
merged 1 commit into from
Jun 23, 2022
Merged
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
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