From 163327fae24ea89df4aa848de449dbfec15f2bf8 Mon Sep 17 00:00:00 2001 From: Asaf Romano Date: Mon, 16 Apr 2012 21:40:47 +0300 Subject: [PATCH] Bug 745466 - initWithPath fails for "~". r=bz. sr=bsmedberg. --- xpcom/io/nsLocalFileUnix.cpp | 8 +++++--- xpcom/tests/unit/test_bug745466.js | 6 ++++++ xpcom/tests/unit/xpcshell.ini | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 xpcom/tests/unit/test_bug745466.js diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp index 416fca451d6..57cef5438eb 100644 --- a/xpcom/io/nsLocalFileUnix.cpp +++ b/xpcom/io/nsLocalFileUnix.cpp @@ -334,7 +334,7 @@ nsLocalFile::Clone(nsIFile **file) NS_IMETHODIMP nsLocalFile::InitWithNativePath(const nsACString &filePath) { - if (Substring(filePath, 0, 2).EqualsLiteral("~/")) { + if (filePath.Equals("~") || Substring(filePath, 0, 2).EqualsLiteral("~/")) { nsCOMPtr homeDir; nsCAutoString homePath; if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_HOME_DIR, @@ -342,8 +342,10 @@ nsLocalFile::InitWithNativePath(const nsACString &filePath) NS_FAILED(homeDir->GetNativePath(homePath))) { return NS_ERROR_FAILURE; } - - mPath = homePath + Substring(filePath, 1, filePath.Length() - 1); + + mPath = homePath; + if (filePath.Length() > 2) + mPath.Append(Substring(filePath, 1, filePath.Length() - 1)); } else { if (filePath.IsEmpty() || filePath.First() != '/') return NS_ERROR_FILE_UNRECOGNIZED_PATH; diff --git a/xpcom/tests/unit/test_bug745466.js b/xpcom/tests/unit/test_bug745466.js new file mode 100644 index 00000000000..22a911ac524 --- /dev/null +++ b/xpcom/tests/unit/test_bug745466.js @@ -0,0 +1,6 @@ +Components.utils.import("resource://gre/modules/FileUtils.jsm"); + +function run_test() +{ + do_check_true(FileUtils.File("~").equals(FileUtils.getDir("Home", []))); +} diff --git a/xpcom/tests/unit/xpcshell.ini b/xpcom/tests/unit/xpcshell.ini index 785e86fb4e2..e173c7d1586 100644 --- a/xpcom/tests/unit/xpcshell.ini +++ b/xpcom/tests/unit/xpcshell.ini @@ -45,3 +45,4 @@ fail-if = os == "android" [test_versioncomparator.js] [test_comp_no_aslr.js] fail-if = os != "win" +[test_bug745466.js]