Repository navigation
Fix an error when the first change is a binary - #75
Merged
Merged
Conversation
This fixes a bug where, in a diff where the first change is a binary
file, unidiff errors with
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 538, in from_filename
instance = cls(f)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 421, in __init__
self._parse(data, encoding=encoding, metadata_only=metadata_only)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 520, in _parse
patch_info.append(line)
AttributeError: 'NoneType' object has no attribute 'append'
```
Reproduction steps:
```
\# Requires `go` to generate example binaries, but you can replace them
\# with any two different binaries from any source
$ echo "package main\nfunc main(){}" > binary_a.go
$ go build binary_a.go
$ echo "package main\nimport \"fmt\"\nfunc main(){fmt.Println(\"HI\")}" > binary_b.go
$ go build binary_b.go
$ diff binary_a binary_b > changes.diff
$ cat changes.diff
Binary files binary_a and binary_b differ
$ python3
>>> from unidiff import PatchSet
>>> PatchSet.from_filename('./changes.diff')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 538, in from_filename
instance = cls(f)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 421, in __init__
self._parse(data, encoding=encoding, metadata_only=metadata_only)
File "/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.1_5/lib/python3.9/site-packages/unidiff/patch.py", line 520, in _parse
patch_info.append(line)
AttributeError: 'NoneType' object has no attribute 'append'
>>>
```
Owner
|
Nice catch! Thanks for the fix 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a bug where, in a diff where the first change is a binary file, unidiff errors with
Reproduction steps: