strip null bytes on readString

This commit is contained in:
DavidVentura
2024-01-29 16:31:56 +01:00
parent 3d5d250807
commit c8259c95fa
+4 -1
View File
@@ -44,7 +44,10 @@ DataView.prototype.readByteArray = function (len) {
}; };
DataView.prototype.readString = function (len) { DataView.prototype.readString = function (len) {
const ba = this.readByteArray(len); const ba = this.readByteArray(len);
return String.fromCharCode.apply(null, new Uint8Array(ba.buffer)); const s = String.fromCharCode.apply(null, new Uint8Array(ba.buffer));
const nullByte = s.indexOf("\0");
if (nullByte !== -1) return s.substring(0, nullByte);
return s;
}; };
declare global { declare global {