Backed out changeset 65e974428cdb (bug 1847572) for causing gtest crashes. CLOSED TREE

This commit is contained in:
Stanca Serban 2023-09-07 22:42:14 +03:00
parent 200ab4e63d
commit 04ab13cb66
3 changed files with 12 additions and 64 deletions

View file

@ -803,7 +803,6 @@ if (AppConstants.platform == "win") {
});
} else {
const homeDir = Services.dirsvc.get("Home", Ci.nsIFile).path;
const homeBase = AppConstants.platform == "macosx" ? "/Users" : "/home";
testcases.push({
input: "~",
@ -815,16 +814,6 @@ if (AppConstants.platform == "win") {
fixedURI: `file://${homeDir}/foo`,
protocolChange: true,
});
testcases.push({
input: "~foo",
fixedURI: `file://${homeBase}/foo`,
protocolChange: true,
});
testcases.push({
input: "~foo/bar",
fixedURI: `file://${homeBase}/foo/bar`,
protocolChange: true,
});
testcases.push({
input: "/some/file.txt",
fixedURI: "file:///some/file.txt",

View file

@ -307,35 +307,19 @@ nsLocalFile::Clone(nsIFile** aFile) {
NS_IMETHODIMP
nsLocalFile::InitWithNativePath(const nsACString& aFilePath) {
if (!aFilePath.IsEmpty() && aFilePath.First() == '~') {
if (aFilePath.Length() == 1 || aFilePath.CharAt(1) == '/') {
// Home dir for the current user
if (aFilePath.EqualsLiteral("~") ||
Substring(aFilePath, 0, 2).EqualsLiteral("~/")) {
nsCOMPtr<nsIFile> homeDir;
nsAutoCString homePath;
if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_HOME_DIR,
getter_AddRefs(homeDir))) ||
if (NS_FAILED(
NS_GetSpecialDirectory(NS_OS_HOME_DIR, getter_AddRefs(homeDir))) ||
NS_FAILED(homeDir->GetNativePath(homePath))) {
return NS_ERROR_FAILURE;
}
mPath = homePath;
if (aFilePath.Length() > 2) {
mPath.Append(Substring(aFilePath, 1));
}
} else {
// Home dir for an arbitrary user e.g. `~foo/bar` -> `/home/foo/bar`
// (`/Users/foo/bar` on Mac). The accurate way to get this directory
// is with `getpwnam`, but we would like to avoid doing blocking
// filesystem I/O while creating an `nsIFile`.
mPath =
#ifdef XP_MACOSX
"/Users/"_ns
#else
"/home/"_ns
#endif
+ Substring(aFilePath, 1);
mPath.Append(Substring(aFilePath, 1, aFilePath.Length() - 1));
}
} else {
if (aFilePath.IsEmpty() || aFilePath.First() != '/') {

View file

@ -160,31 +160,6 @@ TEST(TestFilePreferencesUnix, Simple)
rv = newPath->AppendNative(".."_ns);
ASSERT_EQ(rv, NS_ERROR_FILE_UNRECOGNIZED_PATH);
#ifdef XP_UNIX
nsAutoCString homePath;
NS_GetSpecialDirectory(NS_OS_HOME_DIR, getter_AddRefs(newPath));
newPath->GetNativePath(homePath);
newPath->InitWithNativePath("~"_ns);
ASSERT_TRUE(newPath->NativePath().Equals(homePath));
newPath->InitWithNativePath("~/foo"_ns);
ASSERT_TRUE(newPath->NativePath().Equals(homePath + "/foo"_ns));
nsLiteralCString homeBase =
# ifdef XP_MACOSX
"/Users"_ns;
# else
"/home"_ns;
# endif
newPath->InitWithNativePath("~foo"_ns);
ASSERT_TRUE(newPath->NativePath().Equals(homeBase + "/foo"_ns));
newPath->InitWithNativePath("~foo/bar"_ns);
ASSERT_TRUE(newPath->NativePath().Equals(homeBase + "/foo/bar"_ns));
#endif
nsAutoCString trickyPath(tempPath);
trickyPath.AppendLiteral("/allowed/../forbidden_dir/file");
rv = newPath->InitWithNativePath(trickyPath);