From ee0a98b5a2c2447032a0ae736406f1ba0638f77c 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 f4f6e98814cea0..d333422ae8cd74 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -119,7 +119,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(); \