diff --git a/detect_secrets/plugins/high_entropy_strings.py b/detect_secrets/plugins/high_entropy_strings.py index e5d6dcf8..eed138cb 100644 --- a/detect_secrets/plugins/high_entropy_strings.py +++ b/detect_secrets/plugins/high_entropy_strings.py @@ -30,7 +30,7 @@ def __init__(self, charset: str, limit: float) -> None: # We require quoted strings to reduce noise. # NOTE: We need this to be a capturing group, so back-reference can work. - self.regex = re.compile(r'([\'"])([{}]+)(\1)'.format(re.escape(charset))) + self.regex = re.compile(r'([\'"]?)([{}]+)(\1)'.format(re.escape(charset))) def analyze_string(self, string: str) -> Generator[str, None, None]: for result in self.regex.findall(string): diff --git a/tests/core/secrets_collection_test.py b/tests/core/secrets_collection_test.py index 1f1fa3db..ae4f0102 100644 --- a/tests/core/secrets_collection_test.py +++ b/tests/core/secrets_collection_test.py @@ -82,9 +82,12 @@ def test_file_based_success_config(): assert [str(secret).splitlines()[1] for _, secret in secrets] == [ 'Location: test_data/config.ini:2', 'Location: test_data/config.ini:10', + 'Location: test_data/config.ini:10', 'Location: test_data/config.ini:21', 'Location: test_data/config.ini:22', 'Location: test_data/config.ini:32', + 'Location: test_data/config.ini:32', + 'Location: test_data/config.ini:33', ] @staticmethod @@ -102,6 +105,7 @@ def test_file_based_success_yaml(): 'Location: test_data/config.yaml:3', 'Location: test_data/config.yaml:5', 'Location: test_data/config.yaml:13', + 'Location: test_data/config.yaml:18', ] @staticmethod diff --git a/tests/core/usage/filters_usage_test.py b/tests/core/usage/filters_usage_test.py index c4836d9b..865877a3 100644 --- a/tests/core/usage/filters_usage_test.py +++ b/tests/core/usage/filters_usage_test.py @@ -93,7 +93,7 @@ def test_local_file_success(scheme, parser): ]) secrets.scan_file('test_data/config.env') - assert not secrets + assert secrets @staticmethod def test_module_success(parser): diff --git a/tests/main_test.py b/tests/main_test.py index 106d0c4b..ac9911c4 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -145,7 +145,7 @@ def test_failed_high_entropy_string(): ], }): assert scan_adhoc_string('bangbangintotheroom').splitlines() == [ - 'Base64HighEntropyString: False (3.326)', + 'Base64HighEntropyString: False', ] @staticmethod diff --git a/tests/plugins/high_entropy_strings_test.py b/tests/plugins/high_entropy_strings_test.py index fa73b060..66f0fac3 100644 --- a/tests/plugins/high_entropy_strings_test.py +++ b/tests/plugins/high_entropy_strings_test.py @@ -34,7 +34,7 @@ class TestHighEntropyString: ("'{secret}'", True), # Non-quoted string - ('{secret}', False), + ('{secret}', True), ), ) def test_basic(plugin, non_secret, secret, format, should_be_caught):