Whole file
pre-commit/pre-commit-hooks
The author described this change as “Fix parsing of git output with unusual characters”. It counts as a record because the checks below fail on the code as it stood at 5372f44b8 and pass on 4faed34fb, with nothing else changed between the two runs.
Projectpre-commit/pre-commit-hooks
Fix saved2020-07-30
Sharing licenceMIT · LICENSE
Change size+10 −2
What the code was meant to do, written into the code itself as a save note
Fix parsing of git output with unusual characters
The change
| 12 | 12 | EXECUTABLE_VALUES = frozenset(('1', '3', '5', '7')) | |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | def zsplit(s: str) -> List[str]: | |
| 16 | + | s = s.strip('\0') | |
| 17 | + | if s: | |
| 18 | + | return s.split('\0') | |
| 19 | + | else: | |
| 20 | + | return [] | |
| 21 | + | ||
| 22 | + | ||
| 15 | 23 | def check_executables(paths: List[str]) -> int: | |
| 16 | 24 | if sys.platform == 'win32': # pragma: win32 cover | |
| 17 | 25 | return _check_git_filemode(paths) | |
| ⋯ | |||
| 26 | 34 | ||
| 27 | 35 | ||
| 28 | 36 | def _check_git_filemode(paths: Sequence[str]) -> int: | |
| 29 | - | outs = cmd_output('git', 'ls-files', '--stage', '--', *paths) | |
| 37 | + | outs = cmd_output('git', 'ls-files', '-z', '--stage', '--', *paths) | |
| 30 | 38 | seen: Set[str] = set() | |
| 31 | - | for out in outs.splitlines(): | |
| 39 | + | for out in zsplit(outs): | |
| 32 | 40 | metadata, path = out.split('\t') | |
| 33 | 41 | tagmode = metadata.split(' ', 1)[0] | |
| 34 | 42 | ||
The check that tells the two apart
fail→pass·tests/check_executables_have_shebangs_test.py::test_check_git_filemode_passing_unusual_characters
fail→pass·tests/check_executables_have_shebangs_test.py::test_check_zsplit_returns_empty[\x00\x00]
fail→pass·tests/check_executables_have_shebangs_test.py::test_check_zsplit_returns_empty[\x00]
fail→pass·tests/check_executables_have_shebangs_test.py::test_check_zsplit_returns_empty[]
fail→pass·tests/check_executables_have_shebangs_test.py::test_check_zsplits_correctly[\x00f1\x00f2\x00]
fail→pass·tests/check_executables_have_shebangs_test.py::test_check_zsplits_correctly[\x00f1\x00f2]
fail→pass·tests/check_executables_have_shebangs_test.py::test_check_zsplits_correctly[f1\x00f2\x00]
Check file tests/check_executables_have_shebangs_test.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it5372f44b858f6eef834d9632e9960c39c296d448
Broken version dated2020-07-01
Modulepre_commit_hooks.check_executables_have_shebangs
Units changed_check_git_filemode
Fingerprint545c7a8ed17c6392
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in pre-commit/pre-commit-hooks
- 2024-04-20Continues processing JSONs even if hook fails (fixes #1038)
- 2020-09-27Fix #518, provide --enforce-all option to check_added_large_files
- 2019-10-25fix-whitespace: Added test for custom charsets
- 2019-05-15Handle crlf endings in fix-encoding-pragma
- 2017-09-27Fix mixed-line-endings --fix=... when whole file is a different ending
- 2017-06-25Fix bug with the file-contents-sorter hook when processing file that does not end in a newline