Unify ways to select and validate filenames when saving
Categories
(Firefox :: File Handling, defect, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox102 | --- | fixed |
People
(Reporter: enndeakin, Assigned: enndeakin)
References
(Blocks 3 open bugs, Regressed 2 open bugs)
Details
Attachments
(14 files)
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details |
There are at least five different ways in which one can save a file such as an image. However they all use different codepaths that determine the filename differently, and apply different validation rules to the filename.
- Save As
- does use the filename from the content-disposition, but also uses the 'name' if it is not present.
- uses the document title if available
- replaces some invalid extensions but for other invalid extensions, just appends to the existing one (reallyapng.jpeg becomes reallyapng.png but image.pang becomes image.pang.png)
- strips out many illegal characters (more so than drag and copy)
- does not truncate long filenames (such that on Mac, the save button is just disabled and it is unclear why)
- Subfiles saved from save document, complete:
- doesn't use the filename from the content-disposition
- replaces invalid extensions
- truncates long filenames to a maximum of 64 characters
- strips out almost all non-alphanumeric characters
- if the file already exists, adds a number such as '_001', '_002' etc. to the filename
- Drag image to file system:
- doesn't use the filename from the content-disposition
- replaces invalid extensions
- strips out some illegal characters
- does not truncate long filenames
- Mac uses different but identical code for this
- Copy/Paste image to file system
- doesn't use the filename from the content-disposition
- replaces invalid extensions
- strips out some illegal characters
- does not truncate long filenames
- Content-disposition: attachment or download attribute
- filename from the content-disposition overrides the download attribute (this is the correct behaviour)
- doesn't replace invalid extensions
- strips out some illegal characters (a yet still different set than the other types)
- truncates long filenames to a maximum to 138(?) characters
There are other various minor differences. It would be good to unify all of these so that they same rules apply in each case.
Updated•3 years ago
|
Assignee | ||
Comment 1•3 years ago
|
||
Assignee | ||
Comment 2•3 years ago
|
||
Depends on D135950
Assignee | ||
Comment 3•3 years ago
|
||
Depends on D135951
Assignee | ||
Comment 4•3 years ago
|
||
Depends on D135952
Assignee | ||
Comment 5•3 years ago
|
||
Depends on D135953
Assignee | ||
Comment 6•3 years ago
|
||
Depends on D135954
Assignee | ||
Comment 7•3 years ago
|
||
Depends on D135955
Assignee | ||
Comment 8•3 years ago
|
||
Depends on D135956
Assignee | ||
Comment 9•3 years ago
|
||
Depends on D135957
Assignee | ||
Comment 10•3 years ago
|
||
Depends on D135958
Assignee | ||
Comment 11•3 years ago
|
||
No existing tests were modified by these changes, however some behaviour changes with regards
to filenames that currently have no automated tests is described below. Some of the following
might need further investigation to determine whether they are problems or not:
- There are differences between the way that Save Page chooses whether the append the valid extension
to an existing invalid extension versus replacing the invalid extension. Some types -- images and
those listed in forcedExtensionMimetypes -- replace existing invalid extensions, whereas other
types append to any existing invalid extension. - Some empty filenames resulted in filenames like '.jpg' or 'exe'. The behaviour here
uses the default filename of 'index' instead, such that, for example, 'index.jpg' would be used.
This has been applied to all cases, but probably needs some modification. - Save Page can use the web page title when saving a document. This should work but has not been
tested much yet. - Invalid characters are now handled more consistently for all save types, so some variations
of results will apply. For example, '*' is now replaced with a space. Some of the checks that
DownLoadPaths.sanitize does are not yet added. In particular, string.CollapseWhitespace() only
collapses ascii whitespace, but save as also collapses a wide variety of other whitespace
characters. - Long filenames are always cropped at 64 characters. This should ideally be fixed to be
platform-specific. (But save web page, complete currently used 64 characters on all platforms,
other save types don't have any restriction at all.) - May wish to expose the sanitize function (SanitizeFilename) somehow so that DownloadPaths.sanitize
can use the same method.
These differences can be checked by running the new test browser_save_filenames.js without any of
the patches applied.
Oddities (current behaviour and new):
- Plain text and binary types do not get their extensions checked for validity.
- When calling GetFromTypeAndExtension, the extension of image types is ignored. On Mac,
at least, the extension is validated by checking if the specified extension would be
handled by the same application as the primary extension. For me, this is Preview.app
for any image extension. So this means that jpeg, for example, is treated as a valid
extension for a png image. - The test browser_test_data_text_csv.js has a case where there is no filename, so it defaults
to the temporary file that was created when downloading. - On Windows, when saving a file with no content type and an .exe extension, .txt is
appended to the filename. This is done at a later step in validateLeafName in HelperAppDlg.jsm.
This is special-cased (case 54) in the testcase. - Windows does not have a application/x-javascript mime type handler specified by default so
the mime code (in uriloader/exthandler/win) creates a mime info object where the primary
extension is the extension you specified. When the extraMimeEntries gets checked, it adds
the .js extension to the mime info object but at a lower priority. This means that the
.js extension is never applied. This affects a number of testcases, for example, 23 and 24. - Sniffing is done too generically in toolkit/components/mediasniffer/nsMediaSniffer.cpp and
a file web_video1.ogv will be sniffed as application/ogg even though the extension implies
it should be video/ogg. This doesn't cause any effect with the current patches however but
was noticed as a issue to investigate further. - Mac seems to use the extension .dms to refer to unknown binary files. This does happen in some
situations currently, and possibly could still happen when saving some files, but this is
reduced and doesn't appear to show up in any cases with these patches applied. - The name field Content-Disposition is used by contentAreaUtils.js as well as the filename. I'm
not clear of the background behind this, but this special case is kept in just when using this
codepath. - nsWebBrowserPersist::CalculateAndAppendFileExt used to be supplied an original url that was
checked as an alternate, but I can't find a case where that url differs from the regular url
that was supplied. It seems inconsequential though so I just removed this.
Assignee | ||
Comment 12•3 years ago
|
||
Depends on D135951
Assignee | ||
Comment 13•3 years ago
|
||
Depends on D135957
Updated•3 years ago
|
Assignee | ||
Comment 14•3 years ago
|
||
Depends on D135959
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 15•3 years ago
|
||
Comment 16•3 years ago
|
||
Backed out for causing failures on uriloader/exthandler/tests/
- backout: https://hg.mozilla.org/integration/autoland/rev/15cebc1bbdefe8a635edef28b8503b89446105b3
- push: https://treeherder.mozilla.org/jobs?repo=autoland&group_state=expanded&revision=d19cc58e3cab262ccf4f7e908d59f8b08903a67e
- failure logs:
- TEST-UNEXPECTED-FAIL | uriloader/exthandler/tests/mochitest/browser_save_filenames.js | This test exceeded the timeout threshold. It should be rewritten or split up. If that's not possible, use requestLongerTimeout(N), but only as a last resort. -
- TEST-UNEXPECTED-FAIL | uriloader/exthandler/tests/mochitest/browser_auto_close_window.js | Test timed out -
Updated•3 years ago
|
Assignee | ||
Comment 17•3 years ago
|
||
This test involves clicking on a link to a .bin file. In the Mac test environment, this is given the macbinary content type. This test assumes that it will be octet-stream (another valid content type for the bin extension) and sets the alwaysAskBeforeHandling flag for that, so the dialog never shows up. However, another subtest needs octet-stream to prompt as well, so set the always ask for both.
Depends on D138738
Comment 18•3 years ago
|
||
Comment 19•3 years ago
|
||
Backed out 14 changesets (Bug 1746052) for causing build bustages in nsExternalHelperAppService.cpp CLOSED TREE
Log: https://treeherder.mozilla.org/logviewer?job_id=377016321&repo=autoland&lineNumber=31367
https://treeherder.mozilla.org/logviewer?job_id=377017991&repo=autoland&lineNumber=6396
Backout: https://hg.mozilla.org/integration/autoland/rev/53107941679965745bfe12311b44f411aaccb5a7
Comment 20•3 years ago
|
||
Comment 21•3 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/0dfb58ea1a60
https://hg.mozilla.org/mozilla-central/rev/e8245a15c3c9
https://hg.mozilla.org/mozilla-central/rev/d60765ec0794
https://hg.mozilla.org/mozilla-central/rev/6861a1edb0f7
https://hg.mozilla.org/mozilla-central/rev/36e041cca337
https://hg.mozilla.org/mozilla-central/rev/f95c284ca227
https://hg.mozilla.org/mozilla-central/rev/f47ddc358e1a
https://hg.mozilla.org/mozilla-central/rev/a8ab5e1f863c
https://hg.mozilla.org/mozilla-central/rev/ad582bc5019f
https://hg.mozilla.org/mozilla-central/rev/45b3ecacb364
https://hg.mozilla.org/mozilla-central/rev/c5206784e1a6
https://hg.mozilla.org/mozilla-central/rev/fa3172404fd7
https://hg.mozilla.org/mozilla-central/rev/98d24e564a25
https://hg.mozilla.org/mozilla-central/rev/b91422aa4ba1
Assignee | ||
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 22•2 years ago
|
||
since version 101.2 until 103.0b4, firefox no longer saves winrar/zip extensions when downloading those files
Updated•2 years ago
|
Description
•