summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2016-05-30 18:58:30 +0200
committerSebastian Thiel <byronimo@gmail.com>2016-05-30 18:58:30 +0200
commit79fdaf349fa8ad3524f67f1ef86c38ecfc317585 (patch)
tree12850b29d57db446ea3a3060da14bd0312ef0687
parentf5089d9d6c303b47936a741b7bdf37293ec3a1c6 (diff)
parent79c99c0f66c8f3c8d13258376c82125a23b1b5c8 (diff)
downloadgitpython-79fdaf349fa8ad3524f67f1ef86c38ecfc317585.tar.gz
Merge pull request #456 from gitpython-developers/fix-for-invalid-data-in-commits
Add test case as example of Git commit with invalid data
-rw-r--r--git/objects/commit.py6
-rw-r--r--git/test/fixtures/commit_invalid_data6
-rw-r--r--git/test/test_commit.py7
3 files changed, 16 insertions, 3 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py
index dc722f97..58a8912f 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -501,14 +501,14 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
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)
@@ -518,7 +518,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# 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
diff --git a/git/test/fixtures/commit_invalid_data b/git/test/fixtures/commit_invalid_data
new file mode 100644
index 00000000..d112bf2d
--- /dev/null
+++ b/git/test/fixtures/commit_invalid_data
@@ -0,0 +1,6 @@
+tree 9f1a495d7d9692d24f5caedaa89f5c2c32d59368
+parent 492ace2ffce0e426ebeb55e364e987bcf024dd3b
+author E.Azer KoÃoÃoÃoculu <azer@kodfabrik.com> 1306710073 +0300
+committer E.Azer KoÃoÃoÃoculu <azer@kodfabrik.com> 1306710073 +0300
+
+add environjs
diff --git a/git/test/test_commit.py b/git/test/test_commit.py
index 23b7154a..ea8cd9af 100644
--- a/git/test/test_commit.py
+++ b/git/test/test_commit.py
@@ -306,6 +306,13 @@ class TestCommit(TestBase):
# 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 == 'azer@kodfabrik.com', cmt.author.email
+
def test_gpgsig(self):
cmt = self.rorepo.commit()
cmt._deserialize(open(fixture_path('commit_with_gpgsig'), 'rb'))