Chrome,Firefox 在其文件保存对话框中分别将“:”转换为“-”和“_”

Chrome, Firefox converting ":" to "-" and "_" respectively in their file save dialog

我正在尝试使用 FileSaver 库保存文件,该库将使用 Chrome 的 Firefox 的 Save As 对话框。

例如:我有某些文件名,例如 testing:testing1:testing2.csv.

现在当 Save As 对话框弹出时,我看到文件名已转换为

testing-testing1-testing2.csv 对于 Chrome

testing_testing1_testing2.csv 对于 Firefox.

有什么办法可以抑制这种字符转换?

谢谢

没有

文件名不能包含冒号 :(在 Windows 机器上)等字符。如果您想确保您的应用程序与 Windows 兼容,请记住这一点。

这些是不允许使用的字符:

\/:*?"<>|

Firefox 和 Chrome 可能会用破折号/下划线替换所有这些。

文件名只是建议RFC 2616 指出:

19.5.1 Content-Disposition

The Content-Disposition response-header field has been proposed as a means for the origin server to suggest a default filename if the user requests that the content is saved to a file. This usage is derived from the definition of Content-Disposition in RFC 1806 [35].

RFC 1806 进一步指出:

It is important that the receiving MUA not blindly use the suggested filename. The suggested filename SHOULD be checked (and possibly changed) to see that it conforms to local filesystem conventions, does not overwrite an existing file, and does not present a security problem (see Security Considerations below).

长话短说,different file systems have different restrictions on filenames。如果不能按原样使用,浏览器可以自由修复文件名。