Repository navigation
fix(web): 导出文件名按码点截断,避免拆开 emoji - #494
Open
Qiyuanqiii wants to merge 4 commits into
Open
Qiyuanqiii wants to merge 4 commits into
Qiyuanqiii wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
线程导出文件名原先用
.slice(0, 100)按 UTF-16 码元截断。标题为 99 个 ASCII 字符加一个 emoji 时,第 100 个码元正好是 emoji 的高代理项,截断后会留下单独的高代理项,下载文件名中出现替换字符。另一个边界是截断点恰好落在空格或点上:原代码先清理尾随分隔符再截断,截断又会重新制造一个以空格或点结尾的文件名,这在 Windows 上不合法。修复改为先完成非法字符替换和 trim,再按码点截断(
[...clean].slice(0, 100).join("")),最后再清理一次尾随空格和点。上传附件的文件名整理已经采用同样的码点截断写法(web/src/api/client/domains/workspaces.ts:126),导出路径现在与它一致。回归用例在同一个标题上覆盖两个边界:
a+😀+suffix:旧实现最后一个码元是单独的高代理项d83d,新实现保留完整 emoji。a+ 空格 +tail:旧实现结尾是空格("aa "),新实现结尾是"aaa"。验证:
npx vitest run src/v2/thread-export.test.ts:12/12 通过;同一用例在旧实现下失败(期望完整 emoji,实际为单独高代理项)npx vitest run:268 个文件、2608 个用例全部通过npm run typecheck:通过npm run build:通过边界:没有在真实浏览器里实际触发下载;不同浏览器和文件系统对残留非法字符的兜底不在本次范围。100 个码点的长度上限保持不变,也没有改为按字节数限制。