mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Issue #18038: SyntaxError raised during compilation sources with illegal
encoding now always contains an encoding name.
This commit is contained in:
parent
c1f5839412
commit
3af14aaba5
3 changed files with 28 additions and 7 deletions
|
@ -291,20 +291,20 @@ check_coding_spec(const char* line, Py_ssize_t size, struct tok_state *tok,
|
|||
tok->encoding = cs;
|
||||
tok->decoding_state = STATE_NORMAL;
|
||||
}
|
||||
else
|
||||
else {
|
||||
PyErr_Format(PyExc_SyntaxError,
|
||||
"encoding problem: %s", cs);
|
||||
PyMem_FREE(cs);
|
||||
}
|
||||
}
|
||||
} else { /* then, compare cs with BOM */
|
||||
r = (strcmp(tok->encoding, cs) == 0);
|
||||
if (!r)
|
||||
PyErr_Format(PyExc_SyntaxError,
|
||||
"encoding problem: %s with BOM", cs);
|
||||
PyMem_FREE(cs);
|
||||
}
|
||||
}
|
||||
if (!r) {
|
||||
cs = tok->encoding;
|
||||
if (!cs)
|
||||
cs = "with BOM";
|
||||
PyErr_Format(PyExc_SyntaxError, "encoding problem: %s", cs);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue