diff --git a/py/objstr.c b/py/objstr.c index d17b0a68c1868eda620eeaf6cf6cdecc3ea7ea65..51da7a41823fd0208a712271a804d1ab67b8404f 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -1973,8 +1973,8 @@ const mp_obj_type_t mp_type_bytes = { .locals_dict = (mp_obj_dict_t*)&str8_locals_dict, }; -// the zero-length bytes -const mp_obj_str_t mp_const_empty_bytes_obj = {{&mp_type_bytes}, 0, 0, NULL}; +// The zero-length bytes object, with data that includes a null-terminating byte +const mp_obj_str_t mp_const_empty_bytes_obj = {{&mp_type_bytes}, 0, 0, (const byte*)""}; // Create a str/bytes object using the given data. New memory is allocated and // the data is copied across. diff --git a/tests/basics/bytes.py b/tests/basics/bytes.py index d3da15c8e979ee01c6babe421c0e80b66af09f3a..1d97e6b16f7463f582ab8bfe0568b9a115d78b93 100644 --- a/tests/basics/bytes.py +++ b/tests/basics/bytes.py @@ -8,6 +8,9 @@ print(b'\u1234') print(bytes()) print(bytes(b'abc')) +# make sure empty bytes is converted correctly +print(str(bytes(), 'utf-8')) + a = b"123" print(a) print(str(a))