diff --git a/detect_secrets/filters/heuristic.py b/detect_secrets/filters/heuristic.py index 8f65edf4b..5b7dfb444 100644 --- a/detect_secrets/filters/heuristic.py +++ b/detect_secrets/filters/heuristic.py @@ -162,7 +162,9 @@ 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] == '$' + if len(secret) > 0 and secret[0] == '$': + return True + return False def is_indirect_reference(line: str) -> bool: diff --git a/tests/filters/heuristic_filter_test.py b/tests/filters/heuristic_filter_test.py index c408af4c7..6178d4d7c 100644 --- a/tests/filters/heuristic_filter_test.py +++ b/tests/filters/heuristic_filter_test.py @@ -124,6 +124,7 @@ def test_is_templated_secret(line, 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') + assert not filters.heuristic.is_prefixed_with_dollar_sign('') @pytest.mark.parametrize(