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

url: remove unused URL::ToFilePath() #46487

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
62 changes: 0 additions & 62 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1859,68 +1859,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(SetURLConstructor);
}

std::string URL::ToFilePath() const {
if (context_.scheme != "file:") {
return "";
}

#ifdef _WIN32
const char* slash = "\\";
auto is_slash = [] (char ch) {
return ch == '/' || ch == '\\';
};
#else
const char* slash = "/";
auto is_slash = [] (char ch) {
return ch == '/';
};
if ((context_.flags & URL_FLAGS_HAS_HOST) &&
context_.host.length() > 0) {
return "";
}
#endif
std::string decoded_path;
for (const std::string& part : context_.path) {
std::string decoded = PercentDecode(part.c_str(), part.length());
for (char& ch : decoded) {
if (is_slash(ch)) {
return "";
}
}
decoded_path += slash + decoded;
}

#ifdef _WIN32
// TODO(TimothyGu): Use "\\?\" long paths on Windows.

// If hostname is set, then we have a UNC path. Pass the hostname through
// ToUnicode just in case it is an IDN using punycode encoding. We do not
// need to worry about percent encoding because the URL parser will have
// already taken care of that for us. Note that this only causes IDNs with an
// appropriate `xn--` prefix to be decoded.
if ((context_.flags & URL_FLAGS_HAS_HOST) &&
context_.host.length() > 0) {
std::string unicode_host;
if (!ToUnicode(context_.host, &unicode_host)) {
return "";
}
return "\\\\" + unicode_host + decoded_path;
}
// Otherwise, it's a local path that requires a drive letter.
if (decoded_path.length() < 3) {
return "";
}
if (decoded_path[2] != ':' ||
!IsASCIIAlpha(decoded_path[1])) {
return "";
}
// Strip out the leading '\'.
return decoded_path.substr(1);
#else
return decoded_path;
#endif
}

URL URL::FromFilePath(const std::string& file_path) {
URL url("file://");
std::string escaped_file_path;
Expand Down
3 changes: 0 additions & 3 deletions src/node_url.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ class URL {
return SerializeURL(context_, false);
}

// Get the path of the file: URL in a format consumable by native file system
// APIs. Returns an empty string if something went wrong.
std::string ToFilePath() const;
// Get the file URL from native file system path.
static URL FromFilePath(const std::string& file_path);

Expand Down
30 changes: 0 additions & 30 deletions test/cctest/test_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,36 +152,6 @@ TEST_F(URLTest, TruncatedAfterProtocol2) {
EXPECT_EQ(simple.path(), "");
}

TEST_F(URLTest, ToFilePath) {
#define T(url, path) EXPECT_EQ(path, URL(url).ToFilePath())
T("http://example.org/foo/bar", "");

#ifdef _WIN32
T("file:///C:/Program%20Files/", "C:\\Program Files\\");
T("file:///C:/a/b/c?query#fragment", "C:\\a\\b\\c");
T("file://host/path/a/b/c?query#fragment", "\\\\host\\path\\a\\b\\c");
#if defined(NODE_HAVE_I18N_SUPPORT)
T("file://xn--weird-prdj8vva.com/host/a", "\\\\wͪ͊eiͬ͋rd.com\\host\\a");
#else
T("file://xn--weird-prdj8vva.com/host/a",
"\\\\xn--weird-prdj8vva.com\\host\\a");
#endif
T("file:///C:/a%2Fb", "");
T("file:///", "");
T("file:///home", "");
#else
T("file:///", "/");
T("file:///home/user?query#fragment", "/home/user");
T("file:///home/user/?query#fragment", "/home/user/");
T("file:///home/user/%20space", "/home/user/ space");
T("file:///home/us%5Cer", "/home/us\\er");
T("file:///home/us%2Fer", "");
T("file://host/path", "");
#endif

#undef T
}

TEST_F(URLTest, FromFilePath) {
URL file_url;
#ifdef _WIN32
Expand Down