Skip to content

Commit 3036066

Browse files
authored
src: move FromNamespacedPath to path.cc
PR-URL: nodejs#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>
1 parent 8e5d88b commit 3036066

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/node_file.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
30983098
return;
30993099
}
31003100

3101-
node::url::FromNamespacedPath(&initial_file_path.value());
3101+
FromNamespacedPath(&initial_file_path.value());
31023102

31033103
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
31043104
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
@@ -3133,7 +3133,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31333133
return;
31343134
}
31353135

3136-
node::url::FromNamespacedPath(&initial_file_path.value());
3136+
FromNamespacedPath(&initial_file_path.value());
31373137

31383138
for (int i = legacy_main_extensions_with_main_end;
31393139
i < legacy_main_extensions_package_fallback_end;

src/node_url.cc

-13
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,6 @@ std::optional<std::string> FileURLToPath(Environment* env,
544544
#endif // _WIN32
545545
}
546546

547-
// Reverse the logic applied by path.toNamespacedPath() to create a
548-
// namespace-prefixed path.
549-
void FromNamespacedPath(std::string* path) {
550-
#ifdef _WIN32
551-
if (path->compare(0, 8, "\\\\?\\UNC\\", 8) == 0) {
552-
*path = path->substr(8);
553-
path->insert(0, "\\\\");
554-
} else if (path->compare(0, 4, "\\\\?\\", 4) == 0) {
555-
*path = path->substr(4);
556-
}
557-
#endif
558-
}
559-
560547
} // namespace url
561548

562549
} // namespace node

src/node_url.h

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ void ThrowInvalidURL(Environment* env,
8585
std::string FromFilePath(std::string_view file_path);
8686
std::optional<std::string> FileURLToPath(Environment* env,
8787
const ada::url_aggregator& file_url);
88-
void FromNamespacedPath(std::string* path);
8988

9089
} // namespace url
9190

src/path.cc

+13
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,17 @@ void ToNamespacedPath(Environment* env, BufferValue* path) {
314314
#endif
315315
}
316316

317+
// Reverse the logic applied by path.toNamespacedPath() to create a
318+
// namespace-prefixed path.
319+
void FromNamespacedPath(std::string* path) {
320+
#ifdef _WIN32
321+
if (path->starts_with("\\\\?\\UNC\\")) {
322+
*path = path->substr(8);
323+
path->insert(0, "\\\\");
324+
} else if (path->starts_with("\\\\?\\")) {
325+
*path = path->substr(4);
326+
}
327+
#endif
328+
}
329+
317330
} // namespace node

src/path.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ constexpr bool IsWindowsDeviceRoot(const char c) noexcept;
2424
#endif // _WIN32
2525

2626
void ToNamespacedPath(Environment* env, BufferValue* path);
27+
void FromNamespacedPath(std::string* path);
2728

2829
} // namespace node
2930

0 commit comments

Comments
 (0)