Closed
Bug 373640
Opened 17 years ago
Closed 17 years ago
nsIFile.parent throws an exception on reaching top of file system -- should return null
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
mozilla1.9alpha3
People
(Reporter: Waldo, Assigned: Waldo)
References
Details
Attachments
(1 file)
5.33 KB,
patch
|
benjamin
:
review+
|
Details | Diff | Splinter Review |
http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/xpcom/io/nsIFile.idl&rev=1.63&mark=324-327#320 The specification of nsIFile.parent in IDL makes no mention whatsoever of it possibly throwing exceptions. Therefore, except in very anomalous circumstances such as OOM, using it should never throw an exception. Currently, it seems that on Windows using .parent can result in an unrecognized-path exception, which is plain wrong, given the (minimal) specification given in IDL comments. This was discovered when an automated test for bug 332389 broke the Windows testing tinderbox on the assumption that the Windows .parent implementation matched the specification. We absolutely *should not* be having problems conforming to the basic functionality in the nsI(Local)?File specification on any of the major platforms.
Flags: blocking1.9?
Assignee | ||
Comment 1•17 years ago
|
||
I added in a couple lines of effort to avoid copying mWorkingPath when possible, but those changes aren't strictly necessary. I haven't tested this on Windows where it's most likely to fail. (It passes on Linux, for what little it's worth.) I did check that the path of a file object representing C:\ is two characters and that the trailing slash is removed on a Windows machine, which matches what the code looks like it does.
Attachment #258374 -
Flags: review?(benjamin)
Comment 2•17 years ago
|
||
var file = Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties) .get("Drivs", Components.interfaces.nsILocalFile); alert(file.path); // Shows empty string alert(file.parent); // Throws NS_ERROR_FILE_UNRECOGNIZED PATH So I guess it should be: + if (mWorkingPath.Length() == 2) { This will fix another bug as well: var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath("\\\\"); alert(file.path); // Shows "\" alert(file.exists()); // Shows true alert(file.parent.path); // Shows "\\." alert(file.parent.parent); // Shows null With this patch we will return null immediately without going over the bogus "\\." path. Though not stripping the second slash in this case wouldn't be wrong either...
Comment 3•17 years ago
|
||
Sorry, I meant it should be: + if (mWorkingPath.Length() <= 2) {
Comment 4•17 years ago
|
||
Comment on attachment 258374 [details] [diff] [review] Slightly-tested patch It's too bad we don't have a simpler way to check for which platform we're on within a unit test.
Attachment #258374 -
Flags: review?(benjamin) → review+
Updated•17 years ago
|
Flags: blocking1.9? → blocking1.9-
Assignee | ||
Comment 5•17 years ago
|
||
Fixed. I filed bug 375259 for the "Drivs" issue (where an uninitialized file is returned) and bug 375262 for handling UNC paths better, both from comment 2.
Status: NEW → RESOLVED
Closed: 17 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•