Skip to content

Commit 79fdaf3

Browse files
committed
Merge pull request #456 from gitpython-developers/fix-for-invalid-data-in-commits
Add test case as example of Git commit with invalid data
2 parents f5089d9 + 79c99c0 commit 79fdaf3

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

git/objects/commit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,14 @@ def _deserialize(self, stream):
501501

502502
try:
503503
self.author, self.authored_date, self.author_tz_offset = \
504-
parse_actor_and_date(author_line.decode(self.encoding))
504+
parse_actor_and_date(author_line.decode(self.encoding, errors='replace'))
505505
except UnicodeDecodeError:
506506
log.error("Failed to decode author line '%s' using encoding %s", author_line, self.encoding,
507507
exc_info=True)
508508

509509
try:
510510
self.committer, self.committed_date, self.committer_tz_offset = \
511-
parse_actor_and_date(committer_line.decode(self.encoding))
511+
parse_actor_and_date(committer_line.decode(self.encoding, errors='replace'))
512512
except UnicodeDecodeError:
513513
log.error("Failed to decode committer line '%s' using encoding %s", committer_line, self.encoding,
514514
exc_info=True)
@@ -518,7 +518,7 @@ def _deserialize(self, stream):
518518
# The end of our message stream is marked with a newline that we strip
519519
self.message = stream.read()
520520
try:
521-
self.message = self.message.decode(self.encoding)
521+
self.message = self.message.decode(self.encoding, errors='replace')
522522
except UnicodeDecodeError:
523523
log.error("Failed to decode message '%s' using encoding %s", self.message, self.encoding, exc_info=True)
524524
# END exception handling

git/test/fixtures/commit_invalid_data

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tree 9f1a495d7d9692d24f5caedaa89f5c2c32d59368
2+
parent 492ace2ffce0e426ebeb55e364e987bcf024dd3b
3+
author E.Azer Ko�o�o�oculu <[email protected]> 1306710073 +0300
4+
committer E.Azer Ko�o�o�oculu <[email protected]> 1306710073 +0300
5+
6+
add environjs

git/test/test_commit.py

+7
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ def test_serialization_unicode_support(self):
306306
# it appears
307307
cmt.author.__repr__()
308308

309+
def test_invalid_commit(self):
310+
cmt = self.rorepo.commit()
311+
cmt._deserialize(open(fixture_path('commit_invalid_data'), 'rb'))
312+
313+
assert cmt.author.name == u'E.Azer Ko�o�o�oculu', cmt.author.name
314+
assert cmt.author.email == '[email protected]', cmt.author.email
315+
309316
def test_gpgsig(self):
310317
cmt = self.rorepo.commit()
311318
cmt._deserialize(open(fixture_path('commit_with_gpgsig'), 'rb'))

0 commit comments

Comments
 (0)