]> granicus.if.org Git - python/commitdiff
When the UTF-8 conversion to Unicode fails, return an 8-bit string
authorGuido van Rossum <guido@python.org>
Thu, 4 May 2000 15:55:17 +0000 (15:55 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 4 May 2000 15:55:17 +0000 (15:55 +0000)
instead.  This seems more robust than returning an Unicode string with
some unconverted charcters in it.

This still doesn't support getting truly binary data out of Tcl, since
we look for the trailing null byte; but the old (pre-Unicode) code did
this too, so apparently there's no need.  (Plus, I really don't feel
like finding out how Tcl deals with this in each version.)

Modules/_tkinter.c

index 882715f12db574fc50e26ca1c3249084c95b49c1..6c3beef01eb25eb147a923346ee3d0e1afbc7b15 100644 (file)
@@ -654,7 +654,11 @@ Tkapp_Call(self, args)
                else {
                        /* Convert UTF-8 to Unicode string */
                        p = strchr(p, '\0');
-                       res = PyUnicode_DecodeUTF8(s, (int)(p-s), "ignore");
+                       res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict");
+                       if (res == NULL) {
+                               PyErr_Clear();
+                               res = PyString_FromStringAndSize(s, (int)(p-s));
+                       }
                }
        }