-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibxml2-python3-unicode-errors.patch
More file actions
32 lines (30 loc) · 1.21 KB
/
libxml2-python3-unicode-errors.patch
File metadata and controls
32 lines (30 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--- libxml2-2.15.1/python/libxml.c~ 2025-10-16 17:49:18.000000000 +0200
+++ libxml2-2.15.1/python/libxml.c 2025-10-18 12:06:23.895443826 +0200
@@ -1488,6 +1488,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
PyObject *message;
PyObject *result;
char str[1024];
+ unsigned char *ptr = (unsigned char *)str;
if (libxml_xmlPythonErrorFuncHandler == NULL) {
va_start(ap, msg);
@@ -1498,12 +1499,20 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
vsnprintf(str, sizeof(str), msg, ap);
va_end(ap);
+#if PY_MAJOR_VERSION >= 3
+ /* Ensure the error string doesn't start at UTF8 continuation. */
+ while (*ptr && (*ptr & 0xc0) == 0x80)
+ ptr++;
+#endif
+
list = PyTuple_New(2);
PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
- message = libxml_charPtrConstWrap(str);
+ message = libxml_charPtrConstWrap(ptr);
PyTuple_SetItem(list, 1, message);
result = PyObject_CallObject(libxml_xmlPythonErrorFuncHandler, list);
+ /* Forget any errors caused in the error handler. */
+ PyErr_Clear();
Py_XDECREF(list);
Py_XDECREF(result);
}