8000 Fix bytes.__bytes__ to not truncate at a zero byte (GH-27902) · python/cpython@ae52591 · GitHub
[go: up one dir, main page]

Skip to content

Commit ae52591

Browse files
authored
Fix bytes.__bytes__ to not truncate at a zero byte (GH-27902)
1 parent 24b63c6 commit ae52591

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Lib/test/test_bytes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,14 +982,14 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
982982
type2test = bytes
983983

984984
def test__bytes__(self):
985-
foo = b'foo'
985+
foo = b'foo\x00bar'
986986
self.assertEqual(foo.__bytes__(), foo)
987987
self.assertEqual(type(foo.__bytes__()), self.type2test)
988988

989989
class bytes_subclass(bytes):
990990
pass
991991

992-
bar = bytes_subclass(b'bar')
992+
bar = bytes_subclass(b'bar\x00foo')
993993
self.assertEqual(bar.__bytes__(), bar)
994994
self.assertEqual(type(bar.__bytes__()), self.type2test)
995995

Objects/bytesobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ bytes___bytes___impl(PyBytesObject *self)
17011701
return (PyObject *)self;
17021702
}
17031703
else {
1704-
return PyBytes_FromString(self->ob_sval);
1704+
return PyBytes_FromStringAndSize(self->ob_sval, Py_SIZE(self));
17051705
}
17061706
}
17071707

0 commit comments

Comments
 (0)
0