Skip to content

Commit e727c69

Browse files
committed
scan files with spaces in their name
1 parent cb803c6 commit e727c69

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

detect_secrets/core/baseline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def _get_git_tracked_files(rootdir='.'):
371371
],
372372
stderr=fnull,
373373
)
374-
for filename in git_files.decode('utf-8').split():
374+
for filename in git_files.decode('utf-8').split('\n'):
375375
relative_path = util.get_relative_path_if_in_cwd(rootdir, filename)
376376
if relative_path:
377377
output.append(relative_path)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/python
2+
# Will change this later.
3+
SUPER_SECRET_VALUES = '60b725f10c9c85c70d97880dfe8191b3', '3b5d5c3712955042212316173ccf37be'
4+
5+
6+
def main():
7+
print('Hello world!')
8+
9+
10+
if __name__ == '__main__':
11+
main()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/python
2+
# Will change this later.
3+
SUPER_SEECRET_VALUE = 'c3VwZXIgbG9uZyBzdHJpbmcgc2hvdWxkIGNhdXNlIGVub3VnaCBlbnRyb3B5'
4+
VERY_SECRET_TOO = 'f6CGV4aMM9zedoh3OUNbSakBymo7yplB' # pragma: allowlist secret
5+
6+
7+
def main():
8+
print('Hello world!')
9+
10+
11+
if __name__ == '__main__':
12+
main()

tests/core/baseline_test.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ def get_results(
5555
def test_basic_usage(self, path):
5656
results = self.get_results(path=path)
5757

58-
assert len(results.keys()) == 2
58+
assert len(results.keys()) == 4
5959
assert len(results['test_data/files/file_with_secrets.py']) == 1
6060
assert len(results['test_data/files/tmp/file_with_secrets.py']) == 2
61+
assert len(results['test_data/files/file with secrets.py']) == 2
62+
assert len(results['test_data/files/tmp/file with secrets.py']) == 1
6163

6264
@pytest.mark.parametrize(
6365
'path',
@@ -92,8 +94,8 @@ def test_with_multiple_files(self):
9294

9395
assert len(results['test_data/files/file_with_secrets.py']) == 1
9496
assert len(results['test_data/files/tmp/file_with_secrets.py']) == 2
95-
assert 'test_data/files/file_with_secrets.py' in results
96-
assert 'test_data/files/tmp/file_with_secrets.py' in results
97+
assert 'test_data/files/file with secrets.py' not in results
98+
assert 'test_data/files/tmp/file with secrets.py' not in results
9799

98100
def test_with_multiple_non_existent_files(self):
99101
with mock.patch(
@@ -123,20 +125,25 @@ def test_with_folders_and_files(self):
123125
assert 'test_data/files/file_with_secrets.py' in results
124126
assert 'test_data/files/tmp/file_with_secrets.py' in results
125127
assert 'test_data/files/file_with_no_secrets.py' not in results
128+
assert 'test_data/files/file with secrets.py' in results
129+
assert 'test_data/files/tmp/file with secrets.py' in results
126130
assert 'non-existent-file.B' not in results
127131

128132
def test_exclude_regex(self):
129133
results = self.get_results(exclude_files_regex='tmp*')
130134

131-
assert len(results.keys()) == 1
135+
assert len(results.keys()) == 2
132136
assert 'test_data/files/file_with_secrets.py' in results
137+
assert 'test_data/files/file with secrets.py' in results
133138

134139
def test_exclude_regex_at_root_level(self):
135140
results = self.get_results(exclude_files_regex='file_with_secrets.py')
136141

137142
# All files_with_secrets.py should be ignored, both at the root
138143
# level, and the nested file in tmp.
139-
assert not results
144+
assert len(results.keys()) == 2
145+
assert 'test_data/files/file with secrets.py' in results
146+
assert 'test_data/files/tmp/file with secrets.py' in results
140147

141148
def test_no_files_in_git_repo(self):
142149
with mock_git_calls(
@@ -170,7 +177,7 @@ def test_scan_all_files(self):
170177
path=['test_data/files'],
171178
scan_all_files=True,
172179
)
173-
assert len(results.keys()) == 2
180+
assert len(results.keys()) == 4
174181

175182
def test_scan_all_files_with_bad_symlinks(self):
176183
with mock.patch(

0 commit comments

Comments
 (0)