Closed Bug 180161 Opened 22 years ago Closed 21 years ago

Filenames with # won't save correctly - file name gets truncated

Categories

(Core Graveyard :: File Handling, defect, P4)

defect

Tracking

(Not tracked)

RESOLVED INVALID
mozilla1.6beta

People

(Reporter: bjorn.wiberg, Assigned: bzbarsky)

References

()

Details

(Keywords: helpwanted)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2b) Gecko/20021105
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.2b) Gecko/20021105

Saving a file (e.g. a picture) with a # in its name, e.g. "jn27#003.jpg", will
make Mozilla save it as "jn27" (the last part gets cut off and the file
extension is lost).


Reproducible: Always

Steps to Reproduce:
1. Load a page with a picture with a filename containing #
2. Choose "Save Image As..."
3. Notice the incorrect filename displayed in the dialog.

Actual Results:  
File gets saved with only the part before #, and with no file extension.


Expected Results:  
Save the file as "jn27#003.jpg" instead of "jn27".
.
Assignee: blaker → law
Component: Download Manager → File Handling
similar: bug 177964
I wouldn't say that it's similar to bug 17794 -- that bug caused problems
accessing a file; here, the image or file is correctly accessed but gets an
incorrect name during save.
(Sorry, a small typo -- I meant bug 177964.)
yay, go ben...

Taking. I'll fix this as I rewrite all this crud, but if someone wants to do it
in the meantime, the problem is the use of a URI to get the extension in
contentAreaUtils.js
Assignee: law → bzbarsky
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: helpwanted
OS: Windows XP → All
Priority: -- → P4
Hardware: PC → All
Target Milestone: --- → mozilla1.4beta
This seems to work just fine for me on a current trunk build. (linux)
Is this still a problem for anybody?
I still see this problem....  How exactly did you manage to avoid it?
dunno, I did this:
echo foobar > /tmp/foo#bar
Then I loaded that page in Mozilla (highlighted the text in gnome-terminal, hit
middle mouse button in mozilla's content area)
Then: File->Save Page As
that worked.

After that worked, I copied an image to /tmp/foo#bar, hit reload in my browser
window. image appeared. Then I right-clicked on the image and chose Save Image
As. The filename was displayed as foo#bar in the save dialog, and saving worked.
'#' gets escaped differently in file:// and http:// urls, perhaps?  If you try
the URL in the URL field (save image as on the image there) this is quite broken.
ah, I see. that still fails for me, true.
Target Milestone: mozilla1.4beta → mozilla1.6beta
"the problem is the use of a URI to get the extension in contentAreaUtils.js"

bz, can you explain a bit? I looked at the code and wasn't sure where to fix
this. Is the fix a js fix or does something need to change at a lower level? I
could look into fixing this.
Pratik, the code in question is in getDefaultExtension(). In particular, see
http://lxr.mozilla.org/seamonkey/source/xpfe/communicator/resources/content/contentAreaUtils.js#840
bz,

I put some dump statements in the code and I don't think getDefaultExtension()
or getNormalizedLeafName() is the problem. I think the problem is with
getDefaultFileName(). If I try to save the image noted in the bug,
getDefaultFileName() returns me jn27 instead of jn27#003. (Try doing a view
image and you'll only see jn27 in the title).

See
<http://lxr.mozilla.org/seamonkey/source/xpfe/communicator/resources/content/contentAreaUtils.js#741>.
the filename returned here is jn27.

I feel this is because nsIURL (?) strips off everything after the # character.
It would make sense becase if the URL was index.html#abc, then you'd want the
filename to be index.html.

Reading the initial bug report again, it seems there are 2 issues, one is the
part after # being stripped off and the other is the extension not being used.
On my linux system I only see the first issue. When I save the image, the
filepicker shows jn27.jpeg as the filename.
That could also be, but in that case I wonder why the image works at all; having
a link to "http://foo.com/image#foo.jpeg" should make an HTTP request for
"http://foo.com/image".

And in fact, if I load
http://groups.msn.com/_Secure/0VwDaAuwaoqBR*yThFZuJrMgWfSvAErzV5y!oNDRK0Y3JdLM*sqC7onYUQLq8FX40xW9m7*!JIGcT6emR4Ca!ZsJ!vWpwLl8LoFVUL4wO!nuYsJBQMuNVsQwSDU8noYGB/jn27?dc=4675381664316352864
in my browser (the image url from that page, with the part of the "filename"
after '#' removed) I get the right image.

So in fact the image filename is "jn27" in this case, even on the server.
bz: so eh... per your last comment, isn't this invalid?
Not sure.  I'd need to trace through the code and see where the stuff after the
'#' is lost....

But yes, sounds like it.
Yeah, this is invalid (for the '#' part) and worksforme for the extension part.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → INVALID
*** Bug 233170 has been marked as a duplicate of this bug. ***
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.