]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Explicitly convert err->text to Unicode. Fixes #1069.
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 31 Aug 2007 11:17:42 +0000 (11:17 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 31 Aug 2007 11:17:42 +0000 (11:17 +0000)
Python/pythonrun.c

index a0019c4c4b34451393c12a07e49d3179c9cd5a66..eeed820faaa028ce2bed15e8e02d721a82f51662 100644 (file)
@@ -1459,7 +1459,7 @@ PyParser_SetError(perrdetail *err)
 static void
 err_input(perrdetail *err)
 {
-       PyObject *v, *w, *errtype;
+       PyObject *v, *w, *errtype, *errtext;
        PyObject* u = NULL;
        char *msg = NULL;
        errtype = PyExc_SyntaxError;
@@ -1539,8 +1539,17 @@ err_input(perrdetail *err)
                msg = "unknown parsing error";
                break;
        }
-       v = Py_BuildValue("(ziiz)", err->filename,
-                         err->lineno, err->offset, err->text);
+       /* err->text may not be UTF-8 in case of decoding errors.
+          Explicitly convert to an object. */
+       if (!err->text) {
+               errtext = Py_None;
+               Py_INCREF(Py_None);
+       } else {
+               errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text),
+                                              "replace");
+       }
+       v = Py_BuildValue("(ziiN)", err->filename,
+                         err->lineno, err->offset, errtext);
        if (err->text != NULL) {
                PyObject_FREE(err->text);
                err->text = NULL;