diff Parser/tokenizer.c @ 67162:fc834b323f26

Issue #10778: decoding_fgets() decodes the filename from the filesystem encoding instead of UTF-8.
author Victor Stinner <victor.stinner@haypocalc.com>
date Mon, 27 Dec 2010 20:12:13 +0000
parents 3d9ef098daf2
children a0d4eda8da0a
line wrap: on
line diff
--- a/Parser/tokenizer.c	Mon Dec 27 20:10:36 2010 +0000
+++ b/Parser/tokenizer.c	Mon Dec 27 20:12:13 2010 +0000
@@ -545,6 +545,7 @@
 {
     char *line = NULL;
     int badchar = 0;
+    PyObject *filename;
     for (;;) {
         if (tok->decoding_state == STATE_NORMAL) {
             /* We already have a codec associated with
@@ -585,12 +586,16 @@
     if (badchar) {
         /* Need to add 1 to the line number, since this line
            has not been counted, yet.  */
-        PyErr_Format(PyExc_SyntaxError,
-            "Non-UTF-8 code starting with '\\x%.2x' "
-            "in file %.200s on line %i, "
-            "but no encoding declared; "
-            "see http://python.org/dev/peps/pep-0263/ for details",
-            badchar, tok->filename, tok->lineno + 1);
+        filename = PyUnicode_DecodeFSDefault(tok->filename);
+        if (filename != NULL) {
+            PyErr_Format(PyExc_SyntaxError,
+                    "Non-UTF-8 code starting with '\\x%.2x' "
+                    "in file %.200U on line %i, "
+                    "but no encoding declared; "
+                    "see http://python.org/dev/peps/pep-0263/ for details",
+                    badchar, filename, tok->lineno + 1);
+            Py_DECREF(filename);
+        }
         return error_ret(tok);
     }
 #endif