Skip to content

Add test case as example of Git commit with invalid data #456

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Ignore invalid data when decoding commit objects
Previously, GitPython chokes on this while decoding.  Rather than
choking, instead accept the error and replace the invalid bytes by the
� (\x80) char.
  • Loading branch information
nvie committed May 30, 2016
commit 79c99c0f66c8f3c8d13258376c82125a23b1b5c8
6 changes: 3 additions & 3 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,14 @@ def _deserialize(self, stream):

try:
self.author, self.authored_date, self.author_tz_offset = \
parse_actor_and_date(author_line.decode(self.encoding))
parse_actor_and_date(author_line.decode(self.encoding, errors='replace'))
except UnicodeDecodeError:
log.error("Failed to decode author line '%s' using encoding %s", author_line, self.encoding,
exc_info=True)

try:
self.committer, self.committed_date, self.committer_tz_offset = \
parse_actor_and_date(committer_line.decode(self.encoding))
parse_actor_and_date(committer_line.decode(self.encoding, errors='replace'))
except UnicodeDecodeError:
log.error("Failed to decode committer line '%s' using encoding %s", committer_line, self.encoding,
exc_info=True)
Expand All @@ -518,7 +518,7 @@ def _deserialize(self, stream):
# The end of our message stream is marked with a newline that we strip
self.message = stream.read()
try:
self.message = self.message.decode(self.encoding)
self.message = self.message.decode(self.encoding, errors='replace')
except UnicodeDecodeError:
log.error("Failed to decode message '%s' using encoding %s", self.message, self.encoding, exc_info=True)
# END exception handling
Expand Down