Bug 745466 - initWithPath fails for "~". r=bz. sr=bsmedberg.

This commit is contained in:
Asaf Romano 2012-04-16 21:40:47 +03:00
parent 1559635ebd
commit 163327fae2
3 changed files with 12 additions and 3 deletions

View File

@ -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<nsIFile> 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;

View File

@ -0,0 +1,6 @@
Components.utils.import("resource://gre/modules/FileUtils.jsm");
function run_test()
{
do_check_true(FileUtils.File("~").equals(FileUtils.getDir("Home", [])));
}

View File

@ -45,3 +45,4 @@ fail-if = os == "android"
[test_versioncomparator.js]
[test_comp_no_aslr.js]
fail-if = os != "win"
[test_bug745466.js]