From c6befef41711ade0112a0327b5f0662e3ab4a680 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 27 Jun 2024 10:56:33 -0400 Subject: [PATCH] src: move `FromNamespacedPath` to path.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/53540 Reviewed-By: Daniel Lemire Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Ethan Arrowood --- src/node_file.cc | 4 ++-- src/node_url.cc | 13 ------------- src/node_url.h | 1 - src/path.cc | 13 +++++++++++++ src/path.h | 1 + 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index 8717148e6090fa..3800a8e5f600ae 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3098,7 +3098,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { return; } - node::url::FromNamespacedPath(&initial_file_path.value()); + FromNamespacedPath(&initial_file_path.value()); for (int i = 0; i < legacy_main_extensions_with_main_end; i++) { file_path = *initial_file_path + std::string(legacy_main_extensions[i]); @@ -3133,7 +3133,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { return; } - node::url::FromNamespacedPath(&initial_file_path.value()); + FromNamespacedPath(&initial_file_path.value()); for (int i = legacy_main_extensions_with_main_end; i < legacy_main_extensions_package_fallback_end; diff --git a/src/node_url.cc b/src/node_url.cc index bf0de4ccdf12f9..c94537dd714e74 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -544,19 +544,6 @@ std::optional FileURLToPath(Environment* env, #endif // _WIN32 } -// Reverse the logic applied by path.toNamespacedPath() to create a -// namespace-prefixed path. -void FromNamespacedPath(std::string* path) { -#ifdef _WIN32 - if (path->compare(0, 8, "\\\\?\\UNC\\", 8) == 0) { - *path = path->substr(8); - path->insert(0, "\\\\"); - } else if (path->compare(0, 4, "\\\\?\\", 4) == 0) { - *path = path->substr(4); - } -#endif -} - } // namespace url } // namespace node diff --git a/src/node_url.h b/src/node_url.h index 3c77b538b16f8f..39fe9c9c8506e9 100644 --- a/src/node_url.h +++ b/src/node_url.h @@ -85,7 +85,6 @@ void ThrowInvalidURL(Environment* env, std::string FromFilePath(std::string_view file_path); std::optional FileURLToPath(Environment* env, const ada::url_aggregator& file_url); -void FromNamespacedPath(std::string* path); } // namespace url diff --git a/src/path.cc b/src/path.cc index c084d8ff1aef66..cd674cdae18324 100644 --- a/src/path.cc +++ b/src/path.cc @@ -314,4 +314,17 @@ void ToNamespacedPath(Environment* env, BufferValue* path) { #endif } +// Reverse the logic applied by path.toNamespacedPath() to create a +// namespace-prefixed path. +void FromNamespacedPath(std::string* path) { +#ifdef _WIN32 + if (path->starts_with("\\\\?\\UNC\\")) { + *path = path->substr(8); + path->insert(0, "\\\\"); + } else if (path->starts_with("\\\\?\\")) { + *path = path->substr(4); + } +#endif +} + } // namespace node diff --git a/src/path.h b/src/path.h index 3d3354fe32b494..21b98860025691 100644 --- a/src/path.h +++ b/src/path.h @@ -24,6 +24,7 @@ constexpr bool IsWindowsDeviceRoot(const char c) noexcept; #endif // _WIN32 void ToNamespacedPath(Environment* env, BufferValue* path); +void FromNamespacedPath(std::string* path); } // namespace node