8000 fix(surrogateescape): enable on py2, fix tests · gitpython-developers/GitPython@9e4a454 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e4a454

Browse files
committed
fix(surrogateescape): enable on py2, fix tests
1 parent 93d5302 commit 9e4a454

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

git/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,6 @@ def register_surrogateescape():
308308

309309

310310
try:
311-
"hello".decode(defenc, "surrogateescape")
311+
b"100644 \x9f\0aaa".decode(defenc, "surrogateescape")
312312
except:
313313
register_surrogateescape()

git/objects/fun.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from stat import S_ISDIR
33
from git.compat import (
44
byte_ord,
5+
safe_decode,
56
defenc,
67
xrange,
78
text_type,
@@ -76,7 +77,7 @@ def tree_entries_from_data(data):
7677
# default encoding for strings in git is utf8
7778
# Only use the respective unicode object if the byte stream was encoded
7879
name = data[ns:i]
79-
name = name.decode(defenc, 'surrogateescape')
80+
name = safe_decode(name)
8081

8182
# byte is NULL, get next 20
8283
i += 1

git/test/test_fun.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from gitdb.util import bin_to_hex
1717
from gitdb.base import IStream
1818
from gitdb.typ import str_tree_type
19+
from git.compat import PY3
1920

21+
from unittest.case import skipIf
2022
from stat import (
2123
S_IFDIR,
2224
S_IFREG,
@@ -256,6 +258,12 @@ def test_tree_traversal_single(self):
256258
assert entries
257259
# END for each commit
258260

259-
def test_tree_entries_from_data_with_failing_name_decode(self):
261+
@skipIf(PY3, 'odd types returned ... maybe figure it out one day')
262+
def test_tree_entries_from_data_with_failing_name_decode_py2(self):
260263
r = tree_entries_from_data(b'100644 \x9f\0aaa')
261-
assert r == [(b'aaa', 33188, b'\x9f')], r
264+
assert r == [('aaa', 33188, u'\udc9f')], r
265+
266+
@skipIf(not PY3, 'odd types returned ... maybe figure it out one day')
267+
def test_tree_entries_from_data_with_failing_name_decode_py3(self):
268+
r = tree_entries_from_data(b'100644 \x9f\0aaa')
269+
assert r == [(b'aaa', 33188, '\udc9f')], r

0 commit comments

Comments
 (0)
0