Issue #10778: decoding_fgets() decodes the filename from the filesystem
encoding instead of UTF-8.
This commit is contained in:
parent
cb428f0162
commit
83098a4095
|
@ -545,6 +545,7 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
|
||||||
{
|
{
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
int badchar = 0;
|
int badchar = 0;
|
||||||
|
PyObject *filename;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (tok->decoding_state == STATE_NORMAL) {
|
if (tok->decoding_state == STATE_NORMAL) {
|
||||||
/* We already have a codec associated with
|
/* We already have a codec associated with
|
||||||
|
@ -585,12 +586,16 @@ decoding_fgets(char *s, int size, struct tok_state *tok)
|
||||||
if (badchar) {
|
if (badchar) {
|
||||||
/* Need to add 1 to the line number, since this line
|
/* Need to add 1 to the line number, since this line
|
||||||
has not been counted, yet. */
|
has not been counted, yet. */
|
||||||
PyErr_Format(PyExc_SyntaxError,
|
filename = PyUnicode_DecodeFSDefault(tok->filename);
|
||||||
"Non-UTF-8 code starting with '\\x%.2x' "
|
if (filename != NULL) {
|
||||||
"in file %.200s on line %i, "
|
PyErr_Format(PyExc_SyntaxError,
|
||||||
"but no encoding declared; "
|
"Non-UTF-8 code starting with '\\x%.2x' "
|
||||||
"see http://python.org/dev/peps/pep-0263/ for details",
|
"in file %.200U on line %i, "
|
||||||
badchar, tok->filename, tok->lineno + 1);
|
"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);
|
return error_ret(tok);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue