From d033ea614a7975af026ec70d328b9803b1dc39ea Mon Sep 17 00:00:00 2001 From: inoway46 Date: Sat, 1 Aug 2026 22:57:55 +0900 Subject: [PATCH] buffer: search utf16le at every byte offset UTF-16LE searches treated Buffer contents as 16-bit values. This rounded odd offsets down and ignored matches at odd byte positions, even though a Buffer can contain UTF-16LE data beginning at any byte offset. Search encoded string needles byte-by-byte at every offset. Buffer and Uint8Array needles are now compared byte-for-byte in their entirety. This is a breaking change because a match spanning UTF-16 code unit boundaries can be returned before an aligned match. UCS2 searches using Buffer or Uint8Array needles can also return matches that were previously ignored or truncated. Signed-off-by: inoway46 --- doc/api/buffer.md | 12 +++++ src/node_buffer.cc | 62 +++++++++----------------- test/parallel/test-buffer-includes.js | 13 +++++- test/parallel/test-buffer-indexof.js | 63 +++++++++++++++++++++++++-- 4 files changed, 104 insertions(+), 46 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 7e380f7425fb..840e130bfb13 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -2092,6 +2092,10 @@ console.log(buf.fill('zz', 'hex'));