Bug 685236 - Disallow nsIFile::GetNativeTarget on Windows. r?froydnj
MozReview-Commit-ID: JDryRqHcVw2
--- a/xpcom/io/nsIFile.idl
+++ b/xpcom/io/nsIFile.idl
@@ -251,17 +251,19 @@ interface nsIFile : nsISupports
* native filesystem charset.
*
*/
readonly attribute AString target;
[noscript] readonly attribute ACString nativeTarget;
readonly attribute AString path;
[notxpcom,nostdcall,must_use] PathString nativePath();
%{C++
+#ifndef XP_WIN
nsresult GetNativePath(nsACString& aPath);
+#endif
%}
/*
* Returns a human-readable path string.
* The result is deliberately quoted to prevent abuse.
*/
[notxpcom,nostdcall,must_use] UTF8String displayPath();
boolean exists();
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -3553,23 +3553,16 @@ nsLocalFile::SetNativeLeafName(const nsA
nsString
nsLocalFile::NativePath()
{
return mWorkingPath;
}
-nsresult
-nsIFile::GetNativePath(nsACString& aResult)
-{
- //NS_WARNING("This API is lossy. Use GetPath !");
- return NS_CopyUnicodeToNative(NativePath(), aResult);
-}
-
nsCString
nsLocalFile::DisplayPath()
{
nsAutoCString path('[');
AppendUTF16toUTF8(mWorkingPath, path);
path.Append(']');
return path;
}
--- a/xpcom/tests/gtest/TestFile.cpp
+++ b/xpcom/tests/gtest/TestFile.cpp
@@ -26,21 +26,22 @@ static already_AddRefed<nsIFile> NewFile
nsCOMPtr<nsIFile> file =
do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
VerifyResult(rv, "Creating nsIFile");
rv = file->InitWithFile(aBase);
VerifyResult(rv, "InitWithFile");
return file.forget();
}
-static nsCString FixName(const char* aName)
+template <typename char_type>
+static nsTString<char_type> FixName(const char_type* aName)
{
- nsCString name;
+ nsTString<char_type> name;
for (uint32_t i = 0; aName[i]; ++i) {
- char ch = aName[i];
+ char_type ch = aName[i];
// PR_GetPathSeparator returns the wrong value on Mac so don't use it
#if defined(XP_WIN)
if (ch == '/') {
ch = '\\';
}
#endif
name.Append(ch);
}
@@ -374,32 +375,35 @@ static bool TestParent(nsIFile* aBase, n
// Test nsIFile::Normalize and native path setting/getting
static bool TestNormalizeNativePath(nsIFile* aBase, nsIFile* aStart)
{
nsCOMPtr<nsIFile> file = NewFile(aStart);
if (!file)
return false;
- nsAutoCString path;
- nsresult rv = file->GetNativePath(path);
- VerifyResult(rv, "GetNativePath");
+ auto path = file->NativePath();
+#ifdef XP_WIN
+ path.Append(FixName(u"/./.."));
+ nsresult rv = file->InitWithPath(path);
+ VerifyResult(rv, "InitWithPath");
+#else
path.Append(FixName("/./.."));
- rv = file->InitWithNativePath(path);
+ nsresult rv = file->InitWithNativePath(path);
VerifyResult(rv, "InitWithNativePath");
+#endif
rv = file->Normalize();
VerifyResult(rv, "Normalize");
- rv = file->GetNativePath(path);
- VerifyResult(rv, "GetNativePath (after normalization)");
+ path = file->NativePath();
- nsAutoCString basePath;
- rv = aBase->GetNativePath(basePath);
+ auto basePath = aBase->NativePath();
VerifyResult(rv, "GetNativePath (base)");
- EXPECT_TRUE(path.Equals(basePath)) << "Incorrect normalization: " << path.get() << " - " << basePath.get();
+ EXPECT_TRUE(path.Equals(basePath)) << "Incorrect normalization: " <<
+ file->DisplayPath().get() << " - " << aBase->DisplayPath().get();
if (!path.Equals(basePath)) {
return false;
}
return true;
}
TEST(TestFile, Tests)