From ed8353878dbc7b3a4c0d33d22c08971b4f7b001c Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 27 Feb 2026 16:26:24 +0100 Subject: [PATCH 1/5] JSC fix utf8 string creation --- Core/Node-API/Source/js_native_api_javascriptcore.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/Node-API/Source/js_native_api_javascriptcore.cc b/Core/Node-API/Source/js_native_api_javascriptcore.cc index 55832166..623635c9 100644 --- a/Core/Node-API/Source/js_native_api_javascriptcore.cc +++ b/Core/Node-API/Source/js_native_api_javascriptcore.cc @@ -7,8 +7,6 @@ #include #include #include -#include -#include struct napi_callback_info__ { napi_value newTarget; @@ -108,9 +106,11 @@ namespace { return JSStringCreateWithUTF8CString(string); } - std::u16string u16str{std::wstring_convert< - std::codecvt_utf8_utf16, char16_t>{}.from_bytes(string, string + length)}; - return JSStringCreateWithCharacters(reinterpret_cast(u16str.data()), u16str.size()); + // Create a null-terminated copy so JSStringCreateWithUTF8CString can be + // used directly, avoiding the deprecated and error-prone + // std::wstring_convert / std::codecvt_utf8_utf16 path. + std::string str(string, length); + return JSStringCreateWithUTF8CString(str.c_str()); } JSString(JSStringRef string) From 30fa498e064c848e0f20544e9f103b89ebac763b Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 27 Feb 2026 16:31:38 +0100 Subject: [PATCH 2/5] reduced comment for clarity --- Core/Node-API/Source/js_native_api_javascriptcore.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Core/Node-API/Source/js_native_api_javascriptcore.cc b/Core/Node-API/Source/js_native_api_javascriptcore.cc index 623635c9..f429316d 100644 --- a/Core/Node-API/Source/js_native_api_javascriptcore.cc +++ b/Core/Node-API/Source/js_native_api_javascriptcore.cc @@ -106,9 +106,7 @@ namespace { return JSStringCreateWithUTF8CString(string); } - // Create a null-terminated copy so JSStringCreateWithUTF8CString can be - // used directly, avoiding the deprecated and error-prone - // std::wstring_convert / std::codecvt_utf8_utf16 path. + // Create a null-terminated copy so JSStringCreateWithUTF8CString can be used directly std::string str(string, length); return JSStringCreateWithUTF8CString(str.c_str()); } From 3cd8d33b14b03b1b4b7aafbe250e448fa1df208b Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 27 Feb 2026 17:05:34 +0100 Subject: [PATCH 3/5] \0 char test --- Tests/UnitTests/Scripts/tests.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/UnitTests/Scripts/tests.ts b/Tests/UnitTests/Scripts/tests.ts index 51128709..5f3c99f7 100644 --- a/Tests/UnitTests/Scripts/tests.ts +++ b/Tests/UnitTests/Scripts/tests.ts @@ -1261,6 +1261,14 @@ describe("TextDecoder", function () { expect(result).to.equal("World"); }); + it("should decode a Uint8Array containing a null byte", function () { + const decoder = new TextDecoder(); + const encoded = new Uint8Array([72, 0, 105]); // "H\0i" + const result = decoder.decode(encoded); + expect(result).to.equal("H\0i"); + expect(result.length).to.equal(3); + }); + it("should decode a TypedArray subarray with non-zero byteOffset", function () { const decoder = new TextDecoder(); const full = new Uint8Array([88, 72, 105]); // "XHi" From 6e3a6145ead71ecf3f1d6d16789a9cf535f13bfd Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 27 Feb 2026 17:28:21 +0100 Subject: [PATCH 4/5] back to utf16 --- Core/Node-API/Source/js_native_api_javascriptcore.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Node-API/Source/js_native_api_javascriptcore.cc b/Core/Node-API/Source/js_native_api_javascriptcore.cc index f429316d..84101197 100644 --- a/Core/Node-API/Source/js_native_api_javascriptcore.cc +++ b/Core/Node-API/Source/js_native_api_javascriptcore.cc @@ -106,9 +106,9 @@ namespace { return JSStringCreateWithUTF8CString(string); } - // Create a null-terminated copy so JSStringCreateWithUTF8CString can be used directly - std::string str(string, length); - return JSStringCreateWithUTF8CString(str.c_str()); + std::u16string u16str{std::wstring_convert< + std::codecvt_utf8_utf16, char16_t>{}.from_bytes(string, string + length)}; + return JSStringCreateWithCharacters(reinterpret_cast(u16str.data()), u16str.size()); } JSString(JSStringRef string) From 5e79d660d707221090e706304cb0fc405dc52394 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Fri, 27 Feb 2026 17:32:20 +0100 Subject: [PATCH 5/5] includes --- Core/Node-API/Source/js_native_api_javascriptcore.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/Node-API/Source/js_native_api_javascriptcore.cc b/Core/Node-API/Source/js_native_api_javascriptcore.cc index 84101197..55832166 100644 --- a/Core/Node-API/Source/js_native_api_javascriptcore.cc +++ b/Core/Node-API/Source/js_native_api_javascriptcore.cc @@ -7,6 +7,8 @@ #include #include #include +#include +#include struct napi_callback_info__ { napi_value newTarget;