From ceec5cc145220db170ed6c75d60d2e918fc7f59f Mon Sep 17 00:00:00 2001 From: yamachu Date: Sun, 19 Jan 2025 16:05:47 +0900 Subject: [PATCH 1/2] src: use std::u8string instead of std::string to pass path constructor Enforce that it is u8 because it was crashing when loading files containing Japanese in Windows, cp392 environment. Fixes: https://github.com/nodejs/node/issues/56650 --- src/node_modules.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/node_modules.cc b/src/node_modules.cc index 4b522a91323c9f..8c5de164f8622b 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -340,12 +340,14 @@ void BindingData::GetNearestParentPackageJSON( ToNamespacedPath(realm->env(), &path_value); std::string path_value_str = path_value.ToString(); + auto path_value_u8str = + std::u8string(path_value_str.begin(), path_value_str.end()); if (slashCheck) { - path_value_str.push_back(kPathSeparator); + path_value_u8str.push_back(kPathSeparator); } auto package_json = - TraverseParent(realm, std::filesystem::path(path_value_str)); + TraverseParent(realm, std::filesystem::path(path_value_u8str)); if (package_json != nullptr) { args.GetReturnValue().Set(package_json->Serialize(realm)); @@ -366,12 +368,14 @@ void BindingData::GetNearestParentPackageJSONType( ToNamespacedPath(realm->env(), &path_value); std::string path_value_str = path_value.ToString(); + auto path_value_u8str = + std::u8string(path_value_str.begin(), path_value_str.end()); if (slashCheck) { - path_value_str.push_back(kPathSeparator); + path_value_u8str.push_back(kPathSeparator); } auto package_json = - TraverseParent(realm, std::filesystem::path(path_value_str)); + TraverseParent(realm, std::filesystem::path(path_value_u8str)); if (package_json == nullptr) { return; From bc1a91e8dc3b96be097afbda643512857cdce04d Mon Sep 17 00:00:00 2001 From: yamachu Date: Mon, 20 Jan 2025 22:31:27 +0900 Subject: [PATCH 2/2] fixup! Format changed cpp file --- src/node_modules.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_modules.cc b/src/node_modules.cc index 8c5de164f8622b..7c1ef73c9445cc 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -369,7 +369,7 @@ void BindingData::GetNearestParentPackageJSONType( std::string path_value_str = path_value.ToString(); auto path_value_u8str = - std::u8string(path_value_str.begin(), path_value_str.end()); + std::u8string(path_value_str.begin(), path_value_str.end()); if (slashCheck) { path_value_u8str.push_back(kPathSeparator); }