From c8259c95fadb7d5f29c964c8c1ca36a163b56e5c Mon Sep 17 00:00:00 2001 From: DavidVentura Date: Mon, 29 Jan 2024 15:29:03 +0100 Subject: [PATCH] strip null bytes on readString --- shim.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shim.ts b/shim.ts index 6cc7702..be4919d 100644 --- a/shim.ts +++ b/shim.ts @@ -44,7 +44,10 @@ DataView.prototype.readByteArray = function (len) { }; DataView.prototype.readString = function (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 {