From 745c2919b6a6003b4fa772f0a011471dbeef4a88 Mon Sep 17 00:00:00 2001 From: Ariel-Moroshko <45500865+Ariel-Moroshko@users.noreply.github.com> Date: Tue, 29 Oct 2024 06:12:54 +0200 Subject: [PATCH] fix(websocket): prevent sending entire buffer when streaming Uint8Array chunks (#3570) * fix(websocket): prevent full buffer send on Uint8Array chunks * Fix formatting and line endings for CI compliance --- src/helper/websocket/index.test.ts | 4 ++-- src/helper/websocket/index.ts | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/helper/websocket/index.test.ts b/src/helper/websocket/index.test.ts index 0e767788..55e6879d 100644 --- a/src/helper/websocket/index.test.ts +++ b/src/helper/websocket/index.test.ts @@ -89,7 +89,7 @@ describe('WSContext', () => { expect(nullURLWS.url).toBeNull() }) it('Should normalize message in send()', () => { - let data: string | ArrayBuffer | null = null + let data: string | ArrayBuffer | Uint8Array | null = null const wsContext = new WSContext({ // eslint-disable-next-line @typescript-eslint/no-unused-vars send(received, _options) { @@ -104,6 +104,6 @@ describe('WSContext', () => { expect(data).toBeInstanceOf(ArrayBuffer) wsContext.send(new Uint8Array(16)) - expect(data).toBeInstanceOf(ArrayBuffer) + expect(data).toBeInstanceOf(Uint8Array) }) }) diff --git a/src/helper/websocket/index.ts b/src/helper/websocket/index.ts index e40baa2d..9976fe18 100644 --- a/src/helper/websocket/index.ts +++ b/src/helper/websocket/index.ts @@ -68,10 +68,7 @@ export class WSContext { this.protocol = init.protocol ?? null } send(source: string | ArrayBuffer | Uint8Array, options?: SendOptions): void { - this.#init.send( - typeof source === 'string' ? source : source instanceof Uint8Array ? source.buffer : source, - options ?? {} - ) + this.#init.send(source, options ?? {}) } raw?: T binaryType: BinaryType = 'arraybuffer'