Specify how filenames from the OS map to File's `name` property
还没有人认领这个 Issue。
评估
调研方向
阅读 File API 中描述 OS 文件名如何成为 File 的名称的语言,然后比较链接的 Encoding 和 HTML 算法。当规范以规范性方式定义无效文件名的处理以及由此产生的 File 行为,不再留下未解决的浏览器差异时,该 issue 就完成了。
由索引模型根据 Issue 内容生成。
描述
I've been testing how files coming from the OS get exposed as File objects, and in particular how filenames that aren't in the OS's default encoding get mapped to the name property.
In Windows systems, filenames are sequences of UTF-16 code units (not UTF-16 encoded text, as is sometimes claimed, because the system APIs don't check for lone surrogates), and as expected, they directly map to a DOMString. An initial BOM doesn't get removed. There doesn't seem to be any browser differences here.
In Unix systems (tested on Fedora Linux; my understanding is all other modern Unix variants/distros work the same), filenames are byte sequences, which are usually taken to be UTF-8. Here's how the various browsers behave on them:
- Firefox does the equivalent of UTF-8 decode without BOM, decoding bytes which aren't valid UTF-8 as a replacement character.
- WebKit does the equivalent of UTF-8 decode without BOM or fail, and handles failures by returning a
Fileobject with the empty string as filename, empty contents, and MIME typeapplication/octet-streaminstead. The language aroundnamein the spec might allow for an empty string to substitute a filename that cannot be decoded, but it doesn't allow the content to be dropped. Note that the resultingFileobject is identical to theFileobject that HTML's "construct the entry list" creates when a file input has no selected files. - Chrome also does the equivalent of UTF-8 decode without BOM or fail, except that for file inputs, any file whose filename isn't UTF-8 gets dropped from the selection. For drag and drop, Chrome behaves the same as WebKit.
Since it doesn't seem good to drop files or replace them by an empty file, even when their filenames don't match the OS's conventions, it seems like it would be best to agree on Firefox's behavior.
- 主要语言
- HTML
- 星标
- 118
- 派生
- 52
- 平均合并
- 9 天 16 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
w3c/FileAPI 的其他 Issue
-
TPAC2026
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 1/5 1 小时以内 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 5/5 一周以上 新手友好度 30/100
相似的 Issue
-
bug priority:normal ready-for-dev
难度 2/5 1-3 小时 新手友好度 88/100
OpenHands/extensions#626 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
avniproject/avni-client#2135 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
-
needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·