Repository navigation
fix(server): support Unicode download filenames - #4563
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: f20b50d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
Collaborator
Author
|
真实 Windows Desktop 前后验证已完成:同一会话、同一
|
liruifengv
approved these changes
Nov 10, 2026
This was referenced Nov 10, 2026
This was referenced Nov 11, 2026
Closed
Merged
5 tasks done
11 tasks
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.

"## Requirement or Bug\n\n修复 Desktop / Web 点击中文等非 ASCII 文件名的本地文件链接时,文件存在且可读取,但预览仍提示「无法读取这个文件」。\n\n## Bug Reproduction Steps\n\n1. 在 workspace 中生成
\n\n## Superseded PR\n\n#2286 仅做 ASCII sanitize;本 PR 的 ASCII fallback + RFC 5987
分析数据/stat/趋势图_20260929_20261028.png。\n2. 在正文中输出该 PNG 的 Markdown 文件链接并点击。\n3. 修复前下载接口返回 500:ERR_INVALID_CHAR: Invalid character in header content [\"content-disposition\"],前端显示「无法读取这个文件」。\n\n## Root Cause\n\n下载路由把原始文件名直接写入Content-Disposition的filename=\"...\"。Node 的 HTTP header 不接受中文等非 Latin-1 字符,因此在发送响应前抛出ERR_INVALID_CHAR。这是响应头编码的根因修复,不改变文件路径解析或图片解码。\n\n## Code Changes\n\ndiff\n download response\n resolve workspace path and file bytes (unchanged)\n- Content-Disposition: filename=\"<raw filename>\"\n+ filename=\"<ASCII fallback>\"\n+ filename*=UTF-8''<percent-encoded original filename> (when needed)\n\n\n- 纯 ASCII 且无需转义的文件名保留原有响应头。\n- 非 ASCII 或需转义的文件名使用 ASCII fallback,并通过 RFC 5987filename*保留原始 UTF-8 文件名。\n- 新增中文目录 + 中文 PNG 文件名回归,覆盖状态码、MIME、响应头和文件字节。\n\n## Behavior Changes and Affected Users\n\n| Behavior | Before | After | Who relies on the old behavior | Escape hatch |\n|---|---|---|---|---|\n| 普通 ASCII 文件名下载 |attachment; filename=\"a.png\"| 响应头保持不变 | Desktop / Web 文件预览及外部下载脚本 | 无需 |\n| 中文等非 ASCII 文件名下载 | 响应返回 500,无法预览 | 返回 200;ASCII fallback + UTF-8filename*| 使用中文路径的 Desktop / Web 用户 | 无需,恢复原本失败的场景 |\n| 文件路径解析与响应字节 | 由 workspace 解析并返回原文件 | 不变 | 所有本地下载调用方 | 无需 |\n\n受影响模块:packages/kap-server的文件下载路由。\n\n验证:\n-packages/kap-server/test/fs.test.ts:66 个用例通过,包含新增中文 PNG 回归。\n-packages/kap-servertypecheck 通过。\n- 仓库 lint 与 kap-server 全量测试结果见最终 CI / 本地回执。\n\n## Checklist\n\n- [x] I have read the CONTRIBUTING document.\n- [ ] I have linked a related issue (external PRs: issue must have a maintainer's/approve).\n- [x] I have added tests that prove my feature works.\n- [x] The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.\n- [x] Rangen-changesetsskill, or this PR needs no changeset.\n- [x] Rangen-docsskill, or this PR needs no doc update.\n\n\n## Real Desktop BEFORE / AFTER\n\n同一会话、同一中文路径与同一 PNG:base 返回 500,修复后返回 200 并实际显示图片,下载字节与原图一致。\n\nfilename*已覆盖其目标并保留 UTF-8 文件名。建议维护者关闭 #2286,避免继续分叉。\n"