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

Avoid IndexError when passing an empty string to is_prefixed_with_dollar_sign #712

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion detect_secrets/filters/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def is_prefixed_with_dollar_sign(secret: str) -> bool:
# false negatives than `is_templated_secret` (e.g. secrets that actually start with a $).
# This is best used with files that actually use this as a means of referencing variables.
# TODO: More intelligent filetype handling?
return secret[0] == '$'
return bool(secret) and secret[0] == '$'


def is_indirect_reference(line: str) -> bool:
Expand Down
13 changes: 10 additions & 3 deletions tests/filters/heuristic_filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,16 @@ def test_is_templated_secret(line, result):
assert bool(list(scan_line(line))) is result


def test_is_prefixed_with_dollar_sign():
assert filters.heuristic.is_prefixed_with_dollar_sign('$secret')
assert not filters.heuristic.is_prefixed_with_dollar_sign('secret')
@pytest.mark.parametrize(
'secret, result',
(
('$secret', True),
('secret', False),
('', False),
),
)
def test_is_prefixed_with_dollar_sign(secret, result):
assert filters.heuristic.is_prefixed_with_dollar_sign(secret) == result


@pytest.mark.parametrize(
Expand Down
Loading