summaryrefslogtreecommitdiff
path: root/git/diff.py
diff options
context:
space:
mode:
authorJonathan Chu <jonathan.chu@me.com>2016-03-15 12:30:34 -0400
committerJonathan Chu <jonathan.chu@me.com>2016-03-15 12:30:34 -0400
commit25f27c86af9901f0135eac20a37573469a9c26ef (patch)
treec981fb38de23eb486b66ac699610f8e7eaec54b8 /git/diff.py
parentb2971489fec32160836519e66ca6b97987c33d0c (diff)
downloadgitpython-25f27c86af9901f0135eac20a37573469a9c26ef.tar.gz
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.
Diffstat (limited to 'git/diff.py')
-rw-r--r--git/diff.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/git/diff.py b/git/diff.py
index 9059091e..062220df 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -365,7 +365,8 @@ class Diff(object):
if not line.startswith(":"):
continue
# END its not a valid diff line
- old_mode, new_mode, a_blob_id, b_blob_id, change_type, path = line[1:].split(None, 5)
+ meta, _, path = line[1:].partition('\t')
+ old_mode, new_mode, a_blob_id, b_blob_id, change_type = meta.split(None, 4)
path = path.strip()
a_path = path
b_path = path