Skip to content

Commit 8f14002

Browse files
anonrigdanielleadams
authored andcommitted
url: remove unused URL::ToFilePath()
PR-URL: #46487 Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f57e7bc commit 8f14002

File tree

3 files changed

+0
-95
lines changed

3 files changed

+0
-95
lines changed

src/node_url.cc

-62
Original file line numberDiff line numberDiff line change
@@ -1847,68 +1847,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
18471847
registry->Register(DomainToUnicode);
18481848
}
18491849

1850-
std::string URL::ToFilePath() const {
1851-
if (context_.scheme != "file:") {
1852-
return "";
1853-
}
1854-
1855-
#ifdef _WIN32
1856-
const char* slash = "\\";
1857-
auto is_slash = [] (char ch) {
1858-
return ch == '/' || ch == '\\';
1859-
};
1860-
#else
1861-
const char* slash = "/";
1862-
auto is_slash = [] (char ch) {
1863-
return ch == '/';
1864-
};
1865-
if ((context_.flags & URL_FLAGS_HAS_HOST) &&
1866-
context_.host.length() > 0) {
1867-
return "";
1868-
}
1869-
#endif
1870-
std::string decoded_path;
1871-
for (const std::string& part : context_.path) {
1872-
std::string decoded = PercentDecode(part.c_str(), part.length());
1873-
for (char& ch : decoded) {
1874-
if (is_slash(ch)) {
1875-
return "";
1876-
}
1877-
}
1878-
decoded_path += slash + decoded;
1879-
}
1880-
1881-
#ifdef _WIN32
1882-
// TODO(TimothyGu): Use "\\?\" long paths on Windows.
1883-
1884-
// If hostname is set, then we have a UNC path. Pass the hostname through
1885-
// ToUnicode just in case it is an IDN using punycode encoding. We do not
1886-
// need to worry about percent encoding because the URL parser will have
1887-
// already taken care of that for us. Note that this only causes IDNs with an
1888-
// appropriate `xn--` prefix to be decoded.
1889-
if ((context_.flags & URL_FLAGS_HAS_HOST) &&
1890-
context_.host.length() > 0) {
1891-
std::string unicode_host;
1892-
if (!ToUnicode(context_.host, &unicode_host)) {
1893-
return "";
1894-
}
1895-
return "\\\\" + unicode_host + decoded_path;
1896-
}
1897-
// Otherwise, it's a local path that requires a drive letter.
1898-
if (decoded_path.length() < 3) {
1899-
return "";
1900-
}
1901-
if (decoded_path[2] != ':' ||
1902-
!IsASCIIAlpha(decoded_path[1])) {
1903-
return "";
1904-
}
1905-
// Strip out the leading '\'.
1906-
return decoded_path.substr(1);
1907-
#else
1908-
return decoded_path;
1909-
#endif
1910-
}
1911-
19121850
URL URL::FromFilePath(const std::string& file_path) {
19131851
URL url("file://");
19141852
std::string escaped_file_path;

src/node_url.h

-3
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ class URL {
177177
return SerializeURL(context_, false);
178178
}
179179

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

test/cctest/test_url.cc

-30
Original file line numberDiff line numberDiff line change
@@ -152,36 +152,6 @@ TEST_F(URLTest, TruncatedAfterProtocol2) {
152152
EXPECT_EQ(simple.path(), "");
153153
}
154154

155-
TEST_F(URLTest, ToFilePath) {
156-
#define T(url, path) EXPECT_EQ(path, URL(url).ToFilePath())
157-
T("http://example.org/foo/bar", "");
158-
159-
#ifdef _WIN32
160-
T("file:///C:/Program%20Files/", "C:\\Program Files\\");
161-
T("file:///C:/a/b/c?query#fragment", "C:\\a\\b\\c");
162-
T("file://host/path/a/b/c?query#fragment", "\\\\host\\path\\a\\b\\c");
163-
#if defined(NODE_HAVE_I18N_SUPPORT)
164-
T("file://xn--weird-prdj8vva.com/host/a", "\\\\wͪ͊eiͬ͋rd.com\\host\\a");
165-
#else
166-
T("file://xn--weird-prdj8vva.com/host/a",
167-
"\\\\xn--weird-prdj8vva.com\\host\\a");
168-
#endif
169-
T("file:///C:/a%2Fb", "");
170-
T("file:///", "");
171-
T("file:///home", "");
172-
#else
173-
T("file:///", "/");
174-
T("file:///home/user?query#fragment", "/home/user");
175-
T("file:///home/user/?query#fragment", "/home/user/");
176-
T("file:///home/user/%20space", "/home/user/ space");
177-
T("file:///home/us%5Cer", "/home/us\\er");
178-
T("file:///home/us%2Fer", "");
179-
T("file://host/path", "");
180-
#endif
181-
182-
#undef T
183-
}
184-
185155
TEST_F(URLTest, FromFilePath) {
186156
URL file_url;
187157
#ifdef _WIN32

0 commit comments

Comments
 (0)