Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module,win: fix long path resolve #53294

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
Local<Value> local_file_path =
anonrig marked this conversation as resolved.
Show resolved Hide resolved
Buffer::Copy(
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))
env->isolate(), file_path.c_str(), file_path.size())
.ToLocalChecked();
BufferValue buff_file_path(isolate, local_file_path);
ToNamespacedPath(env, &buff_file_path);
Expand Down Expand Up @@ -3141,7 +3141,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
Local<Value> local_file_path =
Buffer::Copy(
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))
env->isolate(), file_path.c_str(), file_path.size())
.ToLocalChecked();
BufferValue buff_file_path(isolate, local_file_path);
ToNamespacedPath(env, &buff_file_path);
Expand Down
8 changes: 4 additions & 4 deletions src/node_modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ void BindingData::GetNearestParentPackageJSON(
// Check if the path has a trailing slash. If so, add it after
// ToNamespacedPath() as it will be deleted by ToNamespacedPath()
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==
std::filesystem::path::preferred_separator;
path_value.ToStringView().ends_with(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous line is not needed path_value.ToString() creates an unnecessary string.

Can you also remove this in other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

std::filesystem::path::preferred_separator);

ToNamespacedPath(realm->env(), &path_value);

Expand All @@ -351,8 +351,8 @@ void BindingData::GetNearestParentPackageJSONType(
// Check if the path has a trailing slash. If so, add it after
// ToNamespacedPath() as it will be deleted by ToNamespacedPath()
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==
std::filesystem::path::preferred_separator;
path_value.ToStringView().ends_with(
std::filesystem::path::preferred_separator);

ToNamespacedPath(realm->env(), &path_value);

Expand Down
Loading