From 4f3d25c4c577a5e12b384696e225c12dfc0b6eb6 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:21:35 -0700 Subject: [PATCH] Fix optimization path for unicodeSlice --- ts/test-node/util/unicodeSlice_test.node.ts | 1 + ts/util/unicodeSlice.std.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ts/test-node/util/unicodeSlice_test.node.ts b/ts/test-node/util/unicodeSlice_test.node.ts index 76abc606c9..04efae568c 100644 --- a/ts/test-node/util/unicodeSlice_test.node.ts +++ b/ts/test-node/util/unicodeSlice_test.node.ts @@ -31,6 +31,7 @@ describe('unicodeSlice()', () => { test('multi-byte char', 'x€x', 1, 4, '€', 3); test('multi-byte char slice before end', '€', 1, 3, '', 0); test('multi-byte char slice after start', '€', 2, 4, '', 0); + test('ignores utf-16 length', '€123', 0, 4, '€1', 4); test('emoji', 'x👩‍👩‍👧‍👦x', 1, 26, '👩‍👩‍👧‍👦', 25); test('emoji slice before end', 'x👩‍👩‍👧‍👦x', 1, 25, '', 0); diff --git a/ts/util/unicodeSlice.std.ts b/ts/util/unicodeSlice.std.ts index 1295ce7648..e55dd134fe 100644 --- a/ts/util/unicodeSlice.std.ts +++ b/ts/util/unicodeSlice.std.ts @@ -21,7 +21,7 @@ export function unicodeSlice( end: number ): string { // Optimization: whole string fits into the range, return as is - if (begin === 0 && end >= input.length) { + if (begin === 0 && end >= Buffer.byteLength(input)) { return input; }