File: python3-unicode-errors.patch

package info (click to toggle)
libxml2.9 2.12.7%2Bdfsg%2Breally2.9.14-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,204 kB
  • sloc: ansic: 198,619; xml: 23,237; python: 21,469; sh: 5,062; makefile: 2,110; javascript: 639; php: 365; perl: 67
file content (37 lines) | stat: -rw-r--r-- 1,327 bytes parent folder | download | duplicates (3)
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
33
34
35
36
37
Origin: https://src.fedoraproject.org/rpms/libxml2/blob/master/f/libxml2-2.9.8-python3-unicode-errors.patch
Bug-Upstream: https://bugzilla.gnome.org/show_bug.cgi?id=789714,
              https://gitlab.gnome.org/GNOME/libxml2/issues/64
Bug-Ubuntu: https://launchpad.net/bugs/1869814

--- a/python/libxml.c
+++ b/python/libxml.c
@@ -1621,6 +1621,7 @@
     PyObject *message;
     PyObject *result;
     char str[1000];
+    unsigned char *ptr = (unsigned char *)str;
 
 #ifdef DEBUG_ERROR
     printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
@@ -1637,12 +1638,20 @@
 	    str[999] = 0;
         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 = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
+        /* Forget any errors caused in the error handler. */
+        PyErr_Clear();
         Py_XDECREF(list);
         Py_XDECREF(result);
     }