diff --git a/packages/zero-cache/src/services/dispatcher/websocket-handoff.test.ts b/packages/zero-cache/src/services/dispatcher/websocket-handoff.test.ts index 9448f8e08..19be267a0 100644 --- a/packages/zero-cache/src/services/dispatcher/websocket-handoff.test.ts +++ b/packages/zero-cache/src/services/dispatcher/websocket-handoff.test.ts @@ -114,7 +114,7 @@ describe('dispatcher/websocket-handoff', () => { installWebSocketHandoff( createSilentLogContext(), () => { - throw new Error('really long stri' + 'i'.repeat(150) + 'ng'); + throw new Error('こんにちは' + 'あ'.repeat(150)); }, server, ); @@ -129,11 +129,13 @@ describe('dispatcher/websocket-handoff', () => { expect(error).toMatchInlineSnapshot(` { "code": 1002, - "reason": "Error: really long striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...", + "reason": "Error: こんにちはああああああああああああああああああああああああああああああああ...", } `); // close messages must be less than or equal to 123 bytes: // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close#reason - expect(error.reason.length).toBeLessThanOrEqual(123); + expect(new TextEncoder().encode(error.reason).length).toBeLessThanOrEqual( + 123, + ); }); }); diff --git a/packages/zero-cache/src/services/dispatcher/websocket-handoff.ts b/packages/zero-cache/src/services/dispatcher/websocket-handoff.ts index dc8ec382e..85bc338a6 100644 --- a/packages/zero-cache/src/services/dispatcher/websocket-handoff.ts +++ b/packages/zero-cache/src/services/dispatcher/websocket-handoff.ts @@ -82,8 +82,8 @@ function truncate(val: string, maxBytes = 123) { return val; } val = val.substring(0, maxBytes - 3); - while (encoder.encode(val).length > maxBytes - 3) { - val.substring(0, val.length - 1); + while (encoder.encode(val + '...').length > maxBytes) { + val = val.substring(0, val.length - 1); } return val + '...'; }