Skip to content

Commit 187319a

Browse files
committed
updated for version 7.3.250
Problem: Python: Errors in Unicode characters not handled nicely. Solution: Add the surrogateescape error handler. (lilydjwg)
1 parent bea434d commit 187319a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/if_python3.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,16 @@
6868

6969
static void init_structs(void);
7070

71+
/* The "surrogateescape" error handler is new in Python 3.1 */
72+
#if PY_VERSION_HEX >= 0x030100f0
73+
# define CODEC_ERROR_HANDLER "surrogateescape"
74+
#else
75+
# define CODEC_ERROR_HANDLER NULL
76+
#endif
77+
7178
#define PyInt Py_ssize_t
7279
#define PyString_Check(obj) PyUnicode_Check(obj)
73-
#define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
80+
#define PyString_AsBytes(obj) PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
7481
#define PyString_FreeBytes(obj) Py_XDECREF(bytes)
7582
#define PyString_AsString(obj) PyBytes_AsString(obj)
7683
#define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
@@ -661,8 +668,9 @@ DoPy3Command(exarg_T *eap, const char *cmd)
661668

662669
/* PyRun_SimpleString expects a UTF-8 string. Wrong encoding may cause
663670
* SyntaxError (unicode error). */
664-
cmdstr = PyUnicode_Decode(cmd, strlen(cmd), (char *)ENC_OPT, NULL);
665-
cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", NULL);
671+
cmdstr = PyUnicode_Decode(cmd, strlen(cmd),
672+
(char *)ENC_OPT, CODEC_ERROR_HANDLER);
673+
cmdbytes = PyUnicode_AsEncodedString(cmdstr, "utf-8", CODEC_ERROR_HANDLER);
666674
Py_XDECREF(cmdstr);
667675
PyRun_SimpleString(PyBytes_AsString(cmdbytes));
668676
Py_XDECREF(cmdbytes);
@@ -1463,7 +1471,7 @@ LineToString(const char *str)
14631471
}
14641472
*p = '\0';
14651473

1466-
result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, NULL);
1474+
result = PyUnicode_Decode(tmp, len, (char *)ENC_OPT, CODEC_ERROR_HANDLER);
14671475

14681476
vim_free(tmp);
14691477
return result;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ static char *(features[]) =
709709

710710
static int included_patches[] =
711711
{ /* Add new patch number below this line */
712+
/**/
713+
250,
712714
/**/
713715
249,
714716
/**/

0 commit comments

Comments
 (0)