Open
Bug 476633
Opened 16 years ago
Updated 4 years ago
nsIFile retrieved from drag and drop improperly urlencodes file name when it's already encoded
Categories
(Core :: DOM: Copy & Paste and Drag & Drop, defect, P5)
Tracking
()
UNCONFIRMED
People
(Reporter: EliteBadger, Unassigned)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.5) Gecko/2008121300 SUSE/3.0.5-1.1 Firefox/3.0.5
Build Identifier: Mozilla XULRunner 1.9.0.5 - 2008121300
I'm writing a XUL application. When I drag a file onto my application and it enters my drop handler, the file name is url-encoded in some bizarro-format.
* Consecutive spaces will be encoded. so foo__bar where each _ is a space becomes foo%20_bar
* Percent signs will be escaped, so foo%bar becomes foo%%bar
* The bug happened when I took an already-encoded file like foo%20bar and it became foo%%2520bar (so it both escapes the percent sign and also encodes it!)
The resulting nsIFile is broken, because it thinks that the underlying file doesn't exist.
Reproducible: Always
Steps to Reproduce:
* Get a file from drag and drop
function onFileDrop(event) {
var session = drag_svc.getCurrentSession();
for (var i = 0; i < session.numDropItems; ++i) {
var xfer = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
xfer.addDataFlavor('application/x-moz-file');
session.getData(xfer, i);
var len = {};
var data = {};
try {
xfer.getTransferData('application/x-moz-file', data, len);
var file = data.value.QueryInterface(Components.interfaces.nsIFile);
} catch(e) {
continue;
}
if (!file.exists()) {
err_print("How did you give me a file that doesn't exist?");
return;
}
}
}
* Open Konqueror and create a file named foo%20bar
* Drag the file onto the application whose drop handler is the above code
* The file.exists property will be false and the error will print
Actual Results:
"How did you give me a file that doesn't exist?
Expected Results:
Function exits normally.
The whole URL encoding thing is such a pain to work around, especially the handling of percent signs. Why does it have to be that way?
Updated•16 years ago
|
Component: XPConnect → Drag and Drop
QA Contact: xpconnect → drag-drop
The other buggy thing about this bug is that if I have a file "foo%bar", it becomes "foo%%bar". Fine, but if I then set file.nodeName to "foo%bar" I get a file not found error.
Is there any workaround for this behavior? I don't want my users to see filenames that don't match the file on disk, but it seems really broken to have to keep a display name variable around that translates the Mozilla Wrong Filename (tm) to the one they would expect.
The double-percent thing is a konqueror bug, not a mozilla bug! My bad. Apparently if you create a new file from konqueror and name it foo%bar it becomes foo%%bar. Creating one from the command line via `touch foo%bar' works the way it should.
It's still a little wacko that getting an nsIFile from foo%bar results in an nsIFile object with leafName foo%2520bar, which then fails when you call file.exists().
Comment 3•4 years ago
|
||
Bulk-downgrade of unassigned, >=3 years untouched DOM/Storage bug's priority.
If you have reason to believe this is wrong, please write a comment and ni :jstutte.
Severity: normal → S4
Priority: -- → P5
You need to log in
before you can comment on or make changes to this bug.
Description
•