From df1f04999e0a9eb499cb87c3e95cb2784f1ee9b3 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 25 Sep 2024 23:56:35 +0200 Subject: [PATCH] src: decode native error messages as UTF-8 The native error messages can sometimes contain e.g. path content that are typically passed in as chars with UTF8-encoded code points. The native error throwing code previously always decode the chars as Latin-1, which would be incorrect. PR-URL: https://github.com/nodejs/node/pull/55024 Reviewed-By: Chengzhong Wu Reviewed-By: James M Snell --- src/node_errors.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/node_errors.h b/src/node_errors.h index ee99e2caf3c5f9..ac07b96b5cad0f 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -112,7 +112,11 @@ void OOMErrorHandler(const char* location, const v8::OOMDetails& details); std::string message = SPrintF(format, std::forward(args)...); \ v8::Local js_code = OneByteString(isolate, #code); \ v8::Local js_msg = \ - OneByteString(isolate, message.c_str(), message.length()); \ + v8::String::NewFromUtf8(isolate, \ + message.c_str(), \ + v8::NewStringType::kNormal, \ + message.length()) \ + .ToLocalChecked(); \ v8::Local e = v8::Exception::type(js_msg) \ ->ToObject(isolate->GetCurrentContext()) \ .ToLocalChecked(); \