Match Node.js v24 behavior for napi_get_value_string_utf8 handling of NAPI_AUTO_LENGTH (#20698)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Jarred Sumner
2025-07-02 20:10:08 -07:00
committed by GitHub
parent 0b9bab34d8
commit 8b321cc1c6
2 changed files with 4 additions and 9 deletions

View File

@@ -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<unsigned char> writable_byte_slice(reinterpret_cast<unsigned char*>(buf),
EncodeTo == NapiStringEncoding::utf16

View File

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