Skip to content

Commit 7b9c0c7

Browse files
committed
Split diff line by '\t' for metadata and path
This protects against `.split(None)` which uses consecutive whitespace as a separator to overlook paths where a single space is the filename. For example, in this diff line: line = ':100644 000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 D ' The deleted file is a file named ' ' (just one space). It's entirely possible to commit this, remove, and to produce the following output from `git diff`: git diff --name-status <SHA1> <SHA2> D M path/to/another/file.py ... This would cause the initial `.split(None, 5)` to fail as it will count all consecutive whitespace as a separator, disregarding the ' ' (single space) filename.
1 parent 5b60803 commit 7b9c0c7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

git/diff.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ def _index_from_raw_format(cls, repo, stream):
327327
if not line.startswith(":"):
328328
continue
329329
# END its not a valid diff line
330-
old_mode, new_mode, a_blob_id, b_blob_id, change_type, path = line[1:].split(None, 5)
330+
meta, _, path = line[1:].partition('\t')
331+
old_mode, new_mode, a_blob_id, b_blob_id, change_type = meta.split(None, 4)
331332
path = path.strip()
332333
a_path = path
333334
b_path = path

0 commit comments

Comments
 (0)