1
0
forked from aniani/vim

patch 8.2.2178: Python 3: non-utf8 character cannot be handled

Problem:    Python 3: non-utf8 character cannot be handled.
Solution:   Change the string decode. (Björn Linse, closes #1053)
This commit is contained in:
Bram Moolenaar
2020-12-21 16:03:02 +01:00
parent ef2dff52de
commit 2e2f52a4a0
6 changed files with 34 additions and 9 deletions

View File

@@ -130,10 +130,11 @@ StringToChars(PyObject *obj, PyObject **todecref)
{
PyObject *bytes;
if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT,
ERRORS_ENCODE_ARG)))
return NULL;
if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1
if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1
|| str == NULL)
{
Py_DECREF(bytes);
@@ -4243,7 +4244,8 @@ StringToLine(PyObject *obj)
}
else if (PyUnicode_Check(obj))
{
if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT,
ERRORS_ENCODE_ARG)))
return NULL;
if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1
@@ -6290,11 +6292,11 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookup_dict)
PyObject *bytes;
char_u *str;
bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL);
bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, ERRORS_ENCODE_ARG);
if (bytes == NULL)
return -1;
if(PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1)
if (PyBytes_AsStringAndSize(bytes, (char **) &str, NULL) == -1)
return -1;
if (str == NULL)
return -1;