Skip to content

Commit 25f27c8

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 b297148 commit 25f27c8

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
@@ -365,7 +365,8 @@ def _index_from_raw_format(cls, repo, stream):
365365
if not line.startswith(":"):
366366
continue
367367
# END its not a valid diff line
368-
old_mode, new_mode, a_blob_id, b_blob_id, change_type, path = line[1:].split(None, 5)
368+
meta, _, path = line[1:].partition('\t')
369+
old_mode, new_mode, a_blob_id, b_blob_id, change_type = meta.split(None, 4)
369370
path = path.strip()
370371
a_path = path
371372
b_path = path

0 commit comments

Comments
 (0)