Skip to content

Commit e3a1667

Browse files
author
Jerzy Kozera
committed
Fix handling of files without \n at end of file
1 parent 5c99790 commit e3a1667

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

detect_secrets/core/audit.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ def _get_secret_with_context(
248248
if len(output) < end_line - start_line + 1:
249249
# This handles the case of a short file.
250250
num_lines_in_file = int(subprocess.check_output([
251-
'wc',
252-
'-l',
251+
'grep', # https://stackoverflow.com/a/38870057
252+
'-c', # - 'wc -l' cannot be used here because if the last char
253+
'', # of the file isn't \n, then the last line isn't counted
253254
filename,
254255
]).decode('utf-8').split()[0])
255256

0 commit comments

Comments
 (0)