Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork941
Split diff line by '\t' for metadata and path#398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This protects against `.split(None)` which uses consecutive whitespaceas a separator to overlook paths where a single space is the filename.For example, in this diff line:line = ':100644 000000e69de290000000000000000000000000000000000000000 D 'The deleted file is a file named ' ' (just one space). It's entirelypossible to commit this, remove, and to produce the following outputfrom `git diff`:git diff --name-status <SHA1> <SHA2>DM path/to/another/file.py...This would cause the initial `.split(None, 5)` to fail as it will countall consecutive whitespace as a separator, disregarding the ' ' (singlespace) filename.
Thanks for the elaborate explanation and the fix! Do you think it's feasible to add a test for this as well, maybe with a fixture? |
And thanks for the quick response@Byron! :) Sure thing, I was just looking into that after I created this PR actually. I'll take a look at the current tests tonight and will see if I can work something in. I think it should be feasible and definitely worth it. |
This tests the edge case of doing a diff against a single whitespacefilename and returns the proper change type. All other normal usage ofthis diff classmethod should remain unchanged.
Thanks so much, it looks great! |
Split diff line by '\t' for metadata and path
🍻 :) |
What's this PR do?
This protects against
.split(None)
, which uses consecutive whitespace as a separator and may overlook paths where a single space is the filename. While having a filename consisting of only a single space is unlikely in practical usage, it is entirely possible.For example, take this diff line:
Notice there is a tab after the
change_type
and a space for the path. The deleted file is a file named ' ' (just one space) at the git root. To replicate this issue, add and commit this file, then delete and commit. This will produce the following output fromgit diff
: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.