Bug 668361: File ctor should fail if passed a directory. r=sicking

This commit is contained in:
Kyle Huey 2011-07-06 09:35:12 -07:00
Родитель 427c82f3cb
Коммит 91f4a59e95
3 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -424,6 +424,11 @@ nsDOMFile::Initialize(nsISupports* aOwner,
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND);
PRBool isDir;
rv = file->IsDirectory(&isDir);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_FALSE(isDir, NS_ERROR_FILE_IS_DIRECTORY);
mFile = file;
return NS_OK;
}

Просмотреть файл

@ -64,9 +64,18 @@ try {
var nonexistentfile = new File("i/sure/hope/this/does/not/exist/anywhere.txt");
ok(false, "This should never be reached!");
} catch (e) {
ok(true, "Attempt to construct a non-existent file should fail.")
ok(true, "Attempt to construct a non-existent file should fail.");
}
try {
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("CurWorkD", Components.interfaces.nsIFile);
var dirfile = new File(dir);
ok(false, "This should never be reached!");
} catch (e) {
ok(true, "Attempt to construct a file from a directory should fail.");
}
]]>
</script>

Просмотреть файл

@ -110,6 +110,18 @@ FileComponent.prototype =
}
do_check_true(threw, "Passing a random object should fail");
var threw = false
try {
// Directories fail
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var f7 = File(dir)
} catch (e) {
threw = true;
}
do_check_true(threw, "Can't create a File object for a directory");
return true;
},