Fix optimization path for unicodeSlice

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2026-03-16 15:37:51 -05:00
committed by GitHub
parent f87188015e
commit fdfecdb5d9
2 changed files with 2 additions and 1 deletions

View File

@@ -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);

View File

@@ -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;
}