mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #29073: bytearray formatting no longer truncates on first null byte.
This commit is contained in:
parent
af9181a4f2
commit
c9ad8b7a23
3 changed files with 12 additions and 1 deletions
|
@ -388,6 +388,13 @@ class FormatTest(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
raise TestFailed('"%*d"%(maxsize, -127) should fail')
|
raise TestFailed('"%*d"%(maxsize, -127) should fail')
|
||||||
|
|
||||||
|
def test_nul(self):
|
||||||
|
# test the null character
|
||||||
|
testcommon("a\0b", (), 'a\0b')
|
||||||
|
testcommon("a%cb", (0,), 'a\0b')
|
||||||
|
testformat("a%sb", ('c\0d',), 'ac\0db')
|
||||||
|
testcommon(b"a%sb", (b'c\0d',), b'ac\0db')
|
||||||
|
|
||||||
def test_non_ascii(self):
|
def test_non_ascii(self):
|
||||||
testformat("\u20ac=%f", (1.0,), "\u20ac=1.000000")
|
testformat("\u20ac=%f", (1.0,), "\u20ac=1.000000")
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ Release date: TBA
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #29073: bytearray formatting no longer truncates on first null byte.
|
||||||
|
|
||||||
- Issue #28932: Do not include <sys/random.h> if it does not exist.
|
- Issue #28932: Do not include <sys/random.h> if it does not exist.
|
||||||
|
|
||||||
- Issue #28147: Fix a memory leak in split-table dictionaries: setattr()
|
- Issue #28147: Fix a memory leak in split-table dictionaries: setattr()
|
||||||
|
|
|
@ -283,13 +283,15 @@ bytearray_format(PyByteArrayObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *bytes_in, *bytes_out, *res;
|
PyObject *bytes_in, *bytes_out, *res;
|
||||||
char *bytestring;
|
char *bytestring;
|
||||||
|
Py_ssize_t bytesize;
|
||||||
|
|
||||||
if (self == NULL || !PyByteArray_Check(self) || args == NULL) {
|
if (self == NULL || !PyByteArray_Check(self) || args == NULL) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bytestring = PyByteArray_AS_STRING(self);
|
bytestring = PyByteArray_AS_STRING(self);
|
||||||
bytes_in = PyBytes_FromString(bytestring);
|
bytesize = PyByteArray_GET_SIZE(self);
|
||||||
|
bytes_in = PyBytes_FromStringAndSize(bytestring, bytesize);
|
||||||
if (bytes_in == NULL)
|
if (bytes_in == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
bytes_out = _PyBytes_Format(bytes_in, args);
|
bytes_out = _PyBytes_Format(bytes_in, args);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue