mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #8383: pickle and pickletools use surrogatepass error handler when
encoding unicode as utf8 to support lone surrogates and stay compatible with Python 2.x and 3.0
This commit is contained in:
parent
3606760670
commit
485fb56eb8
5 changed files with 14 additions and 6 deletions
|
@ -499,7 +499,7 @@ class _Pickler:
|
|||
|
||||
def save_str(self, obj, pack=struct.pack):
|
||||
if self.bin:
|
||||
encoded = obj.encode('utf-8')
|
||||
encoded = obj.encode('utf-8', 'surrogatepass')
|
||||
n = len(encoded)
|
||||
self.write(BINUNICODE + pack("<i", n) + encoded)
|
||||
else:
|
||||
|
@ -966,7 +966,7 @@ class _Unpickler:
|
|||
|
||||
def load_binunicode(self):
|
||||
len = mloads(b'i' + self.read(4))
|
||||
self.append(str(self.read(len), 'utf-8'))
|
||||
self.append(str(self.read(len), 'utf-8', 'surrogatepass'))
|
||||
dispatch[BINUNICODE[0]] = load_binunicode
|
||||
|
||||
def load_short_binstring(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue