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
|
@ -1227,7 +1227,9 @@ save_unicode(PicklerObject *self, PyObject *obj)
|
|||
if (self->bin) {
|
||||
char pdata[5];
|
||||
|
||||
encoded = PyUnicode_AsUTF8String(obj);
|
||||
encoded = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj),
|
||||
PyUnicode_GET_SIZE(obj),
|
||||
"surrogatepass");
|
||||
if (encoded == NULL)
|
||||
goto error;
|
||||
|
||||
|
@ -3352,7 +3354,7 @@ load_binunicode(UnpicklerObject *self)
|
|||
if (unpickler_read(self, &s, size) < 0)
|
||||
return -1;
|
||||
|
||||
str = PyUnicode_DecodeUTF8(s, size, NULL);
|
||||
str = PyUnicode_DecodeUTF8(s, size, "surrogatepass");
|
||||
if (str == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue