summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-06 17:07:17 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-06 17:07:17 (GMT)
commitd8a1447c9980be5f1d8ae806f7aecd814b1cd6f6 (patch)
treea1966e33692ba9de3966c9760957233f51142cb2 /Objects
parent4a4b67951570a8a0452c77a5ebaa98b9ef9fb712 (diff)
downloadcpython-d8a1447c9980be5f1d8ae806f7aecd814b1cd6f6.zip
cpython-d8a1447c9980be5f1d8ae806f7aecd814b1cd6f6.tar.gz
cpython-d8a1447c9980be5f1d8ae806f7aecd814b1cd6f6.tar.bz2
Issue #22215: Now ValueError is raised instead of TypeError when str or bytes
argument contains not permitted null character or byte.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytesobject.c4
-rw-r--r--Objects/unicodeobject.c10
2 files changed, 7 insertions, 7 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index f0c26c3..63d5a5c 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -593,8 +593,8 @@ PyBytes_AsStringAndSize(PyObject *obj,
if (len != NULL)
*len = PyBytes_GET_SIZE(obj);
else if (strlen(*s) != (size_t)PyBytes_GET_SIZE(obj)) {
- PyErr_SetString(PyExc_TypeError,
- "expected bytes with no null");
+ PyErr_SetString(PyExc_ValueError,
+ "embedded null byte");
return -1;
}
return 0;
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index e7ff126..f5d7b78 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3247,7 +3247,7 @@ PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
wlen2 = wcslen(wstr);
if (wlen2 != wlen) {
PyMem_Free(wstr);
- PyErr_SetString(PyExc_TypeError, "embedded null character");
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
return NULL;
}
@@ -3519,8 +3519,8 @@ PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len,
if (locale_error_handler(errors, &surrogateescape) < 0)
return NULL;
- if (str[len] != '\0' || (size_t)len != strlen(str)) {
- PyErr_SetString(PyExc_TypeError, "embedded null character");
+ if (str[len] != '\0' || (size_t)len != strlen(str)) {
+ PyErr_SetString(PyExc_ValueError, "embedded null byte");
return NULL;
}
@@ -3697,7 +3697,7 @@ PyUnicode_FSConverter(PyObject* arg, void* addr)
size = PyBytes_GET_SIZE(output);
data = PyBytes_AS_STRING(output);
if ((size_t)size != strlen(data)) {
- PyErr_SetString(PyExc_TypeError, "embedded NUL character");
+ PyErr_SetString(PyExc_ValueError, "embedded null byte");
Py_DECREF(output);
return 0;
}
@@ -3741,7 +3741,7 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr)
}
if (findchar(PyUnicode_DATA(output), PyUnicode_KIND(output),
PyUnicode_GET_LENGTH(output), 0, 1) >= 0) {
- PyErr_SetString(PyExc_TypeError, "embedded NUL character");
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
Py_DECREF(output);
return 0;
}