From 41bd55f97f33afa6c3e53808af4c19ae868e15b7 Mon Sep 17 00:00:00 2001 From: mert Date: Wed, 11 Dec 2024 11:54:00 +0300 Subject: [PATCH] util: fix Latin1 decoding to return string output --- src/encoding_binding.cc | 8 +++++--- test/cctest/test_encoding_binding.cc | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/encoding_binding.cc b/src/encoding_binding.cc index a132eeb62306c6..885a0d072312e9 100644 --- a/src/encoding_binding.cc +++ b/src/encoding_binding.cc @@ -286,9 +286,11 @@ void BindingData::DecodeLatin1(const FunctionCallbackInfo& args) { env->isolate(), "The encoded data was not valid for encoding latin1"); } - Local buffer_result = - node::Buffer::Copy(env, result.c_str(), written).ToLocalChecked(); - args.GetReturnValue().Set(buffer_result); + Local output = + String::NewFromUtf8( + env->isolate(), result.c_str(), v8::NewStringType::kNormal, written) + .ToLocalChecked(); + args.GetReturnValue().Set(output); } } // namespace encoding_binding diff --git a/test/cctest/test_encoding_binding.cc b/test/cctest/test_encoding_binding.cc index 06cc36d8f6ae34..d00f285800fa7e 100644 --- a/test/cctest/test_encoding_binding.cc +++ b/test/cctest/test_encoding_binding.cc @@ -26,7 +26,7 @@ bool RunDecodeLatin1(Environment* env, return false; } - *result = try_catch.Exception(); + *result = args[0]; return true; }