src: move FromNamespacedPath to path.cc

PR-URL: https://github.com/nodejs/node/pull/53540
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
Yagiz Nizipli
2024-06-27 10:56:33 -04:00
committed by GitHub
parent 8e5d88b641
commit 303606690f
5 changed files with 16 additions and 16 deletions

View File

@@ -3098,7 +3098,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& 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<Value>& 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;

View File

@@ -544,19 +544,6 @@ std::optional<std::string> 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

View File

@@ -85,7 +85,6 @@ void ThrowInvalidURL(Environment* env,
std::string FromFilePath(std::string_view file_path);
std::optional<std::string> FileURLToPath(Environment* env,
const ada::url_aggregator& file_url);
void FromNamespacedPath(std::string* path);
} // namespace url

View File

@@ -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

View File

@@ -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