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]