From 8b321cc1c68dc2d8b8b0c43356c81e8d7fbb85b0 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 2 Jul 2025 20:10:08 -0700 Subject: [PATCH] Match Node.js v24 behavior for `napi_get_value_string_utf8` handling of `NAPI_AUTO_LENGTH` (#20698) Co-authored-by: Claude --- src/bun.js/bindings/napi.cpp | 6 ------ test/napi/napi.test.ts | 7 ++++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/bun.js/bindings/napi.cpp b/src/bun.js/bindings/napi.cpp index 84c4c70402..fe4efcc582 100644 --- a/src/bun.js/bindings/napi.cpp +++ b/src/bun.js/bindings/napi.cpp @@ -2098,12 +2098,6 @@ napi_status napi_get_value_string_any_encoding(napi_env env, napi_value napiValu return napi_set_last_error(env, napi_ok); } - if (bufsize == NAPI_AUTO_LENGTH) [[unlikely]] { - if (writtenPtr) *writtenPtr = 0; - buf[0] = '\0'; - return napi_set_last_error(env, napi_ok); - } - size_t written; std::span writable_byte_slice(reinterpret_cast(buf), EncodeTo == NapiStringEncoding::utf16 diff --git a/test/napi/napi.test.ts b/test/napi/napi.test.ts index 557158e9b7..bd7dc82586 100644 --- a/test/napi/napi.test.ts +++ b/test/napi/napi.test.ts @@ -1,7 +1,7 @@ import { spawn, spawnSync } from "bun"; import { beforeAll, describe, expect, it } from "bun:test"; import { readdirSync } from "fs"; -import { bunEnv, bunExe, tempDirWithFiles } from "harness"; +import { bunEnv, bunExe, isCI, isMacOS, isMusl, tempDirWithFiles } from "harness"; import { join } from "path"; describe("napi", () => { @@ -185,9 +185,10 @@ describe("napi", () => { expect(result).toEndWith("str: abcdef"); }); - it.todo("copies auto len", async () => { + // TODO: once we upgrade the Node version on macOS and musl to Node v24.3.0, remove this TODO + it.todoIf(isCI && (isMacOS || isMusl))("copies auto len", async () => { const result = await checkSameOutput("test_napi_get_value_string_utf8_with_buffer", ["abcdef", 424242]); - expect(result).toEndWith("str:"); + expect(result).toEndWith("str: abcdef"); }); });