Skip to content

Commit 07ca2a0

Browse files
nlitsmetcalmant
authored andcommitted
Add support for decoding CESU-8 encoded strings. This works around java's broken utf-8 implementation.
1 parent 91edde8 commit 07ca2a0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

javaobj.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
# Python 3+
4848
from io import BytesIO
4949

50+
try:
51+
import ftfy.bad_codecs
52+
javacodec = "utf-8-var"
53+
except ImportError:
54+
javacodec = "utf-8"
55+
5056
# ------------------------------------------------------------------------------
5157

5258
# Module version
@@ -641,7 +647,7 @@ def _readString(self, length_fmt="H"):
641647
"""
642648
(length,) = self._readStruct(">{0}".format(length_fmt))
643649
ba = self.object_stream.read(length)
644-
return to_str(ba)
650+
return to_str(ba.decode(javacodec))
645651

646652
def do_classdesc(self, parent=None, ident=0):
647653
"""

0 commit comments

Comments
 (0)