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
Show file tree
Hide file tree
Changes from all commits
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
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
6 changes: 6 additions & 0 deletions git/test/fixtures/commit_invalid_data
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tree 9f1a495d7d9692d24f5caedaa89f5c2c32d59368
parent 492ace2ffce0e426ebeb55e364e987bcf024dd3b
author E.Azer Ko�o�o�oculu <[email protected]> 1306710073 +0300
committer E.Azer Ko�o�o�oculu <[email protected]> 1306710073 +0300

add environjs
7 changes: 7 additions & 0 deletions git/test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ def test_serialization_unicode_support(self):
# it appears
cmt.author.__repr__()

def test_invalid_commit(self):
cmt = self.rorepo.commit()
cmt._deserialize(open(fixture_path('commit_invalid_data'), 'rb'))

assert cmt.author.name == u'E.Azer Ko�o�o�oculu', cmt.author.name
assert cmt.author.email == '[email protected]', cmt.author.email

def test_gpgsig(self):
cmt = self.rorepo.commit()
cmt._deserialize(open(fixture_path('commit_with_gpgsig'), 'rb'))
Expand Down