mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Add private _PyUnicode_AsUTF8NoNUL() function (GH-111957)
Like PyUnicode_AsUTF8(), but check for embedded null characters.
This commit is contained in:
parent
3932b0f7b1
commit
771bd3c94a
4 changed files with 18 additions and 13 deletions
|
@ -76,16 +76,10 @@ isolation_level_converter(PyObject *str_or_none, const char **result)
|
|||
*result = NULL;
|
||||
}
|
||||
else if (PyUnicode_Check(str_or_none)) {
|
||||
Py_ssize_t sz;
|
||||
const char *str = PyUnicode_AsUTF8AndSize(str_or_none, &sz);
|
||||
const char *str = _PyUnicode_AsUTF8NoNUL(str_or_none);
|
||||
if (str == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (strlen(str) != (size_t)sz) {
|
||||
PyErr_SetString(PyExc_ValueError, "embedded null character");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *level = get_isolation_level(str);
|
||||
if (level == NULL) {
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue