summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2016-10-16 15:09:38 +0200
committerSebastian Thiel <byronimo@gmail.com>2016-10-16 15:09:38 +0200
commit9e4a4545dd513204efb6afe40e4b50c3b5f77e50 (patch)
tree54ffff6c8dba0410693673caa38124a704ac9224
parent93d530234a4f5533aa99c3b897bb56d375c2ae60 (diff)
downloadgitpython-9e4a4545dd513204efb6afe40e4b50c3b5f77e50.tar.gz
fix(surrogateescape): enable on py2, fix tests
-rw-r--r--git/compat.py2
-rw-r--r--git/objects/fun.py3
-rw-r--r--git/test/test_fun.py12
3 files changed, 13 insertions, 4 deletions
diff --git a/git/compat.py b/git/compat.py
index 9c7a43dd..a2403d69 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -308,6 +308,6 @@ def register_surrogateescape():
try:
- "hello".decode(defenc, "surrogateescape")
+ b"100644 \x9f\0aaa".decode(defenc, "surrogateescape")
except:
register_surrogateescape()
diff --git a/git/objects/fun.py b/git/objects/fun.py
index a144ba7e..d5b3f902 100644
--- a/git/objects/fun.py
+++ b/git/objects/fun.py
@@ -2,6 +2,7 @@
from stat import S_ISDIR
from git.compat import (
byte_ord,
+ safe_decode,
defenc,
xrange,
text_type,
@@ -76,7 +77,7 @@ def tree_entries_from_data(data):
# default encoding for strings in git is utf8
# Only use the respective unicode object if the byte stream was encoded
name = data[ns:i]
- name = name.decode(defenc, 'surrogateescape')
+ name = safe_decode(name)
# byte is NULL, get next 20
i += 1
diff --git a/git/test/test_fun.py b/git/test/test_fun.py
index 40d040b9..02f338dd 100644
--- a/git/test/test_fun.py
+++ b/git/test/test_fun.py
@@ -16,7 +16,9 @@ from git.index.fun import (
from gitdb.util import bin_to_hex
from gitdb.base import IStream
from gitdb.typ import str_tree_type
+from git.compat import PY3
+from unittest.case import skipIf
from stat import (
S_IFDIR,
S_IFREG,
@@ -256,6 +258,12 @@ class TestFun(TestBase):
assert entries
# END for each commit
- def test_tree_entries_from_data_with_failing_name_decode(self):
+ @skipIf(PY3, 'odd types returned ... maybe figure it out one day')
+ def test_tree_entries_from_data_with_failing_name_decode_py2(self):
r = tree_entries_from_data(b'100644 \x9f\0aaa')
- assert r == [(b'aaa', 33188, b'\x9f')], r
+ assert r == [('aaa', 33188, u'\udc9f')], r
+
+ @skipIf(not PY3, 'odd types returned ... maybe figure it out one day')
+ def test_tree_entries_from_data_with_failing_name_decode_py3(self):
+ r = tree_entries_from_data(b'100644 \x9f\0aaa')
+ assert r == [(b'aaa', 33188, '\udc9f')], r