Skip to content

Commit

Permalink
test non-ascii characters
Browse files Browse the repository at this point in the history
  • Loading branch information
darkgnotic committed Jan 3, 2025
1 parent 0b2a2a5 commit 973fea2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -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,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '...';
}
Expand Down

0 comments on commit 973fea2

Please sign in to comment.