ByteArray.toString should stop at null bytes
The following snippet reproduces the problem:
const ByteArray = imports.byteArray;
// Behaviour changed from 1.50 to 1.52
const wat = ByteArray.fromArray([97, 98, 99, 100, 0]);
print(`"${wat.toString()}"`);
// New API, GJS 1.54 and later, still has the problem
const wat = Uint8Array.from([97, 98, 99, 100, 0]);
print(`"${ByteArray.toString(wat)}"`);
In 1.50.2, this prints "abcd"
while in 1.52 and master it prints "abcd
without the closing quote. This is because the string returned from toString()
is now "abcd\0"
whereas before it was "abcd"
.
The old behaviour makes the most sense. We should stop at the first null byte, since returning a string with embedded null bytes, while allowed in JS, will behave in unexpected ways such as this example.