Skip to content

fix(server): support Unicode download filenames - #4563

Open
kimi-agent-bot wants to merge 1 commit into
mainfrom
fix/unicode-download-content-disposition
Open

kimi-agent-bot wants to merge 1 commit into
mainfrom
fix/unicode-download-content-disposition

Conversation

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator

Requirement or Bug

修复 Desktop / Web 点击中文等非 ASCII 文件名的本地文件链接时,文件存在且可读取,但预览仍提示「无法读取这个文件」。

Bug Reproduction Steps

  1. 在 workspace 中生成 分析数据/stat/趋势图_20260929_20261028.png。
  2. 在正文中输出该 PNG 的 Markdown 文件链接并点击。
  3. 修复前下载接口返回 500:ERR_INVALID_CHAR: Invalid character in header content ["content-disposition"],前端显示「无法读取这个文件」。

Root Cause

下载路由把原始文件名直接写入 Content-Disposition 的 filename="..."。Node 的 HTTP header 不接受中文等非 Latin-1 字符,因此在发送响应前抛出 ERR_INVALID_CHAR。这是响应头编码的根因修复,不改变文件路径解析或图片解码。

Code Changes

 download response
   resolve workspace path and file bytes (unchanged)
-  Content-Disposition: filename="<raw filename>"
+  filename="<ASCII fallback>"
+  filename*=UTF-8''<percent-encoded original filename> (when needed)
  • 纯 ASCII 且无需转义的文件名保留原有响应头。
  • 非 ASCII 或需转义的文件名使用 ASCII fallback,并通过 RFC 5987 filename* 保留原始 UTF-8 文件名。
  • 新增中文目录 + 中文 PNG 文件名回归,覆盖状态码、MIME、响应头和文件字节。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
普通 ASCII 文件名下载 attachment; filename="a.png" 响应头保持不变 Desktop / Web 文件预览及外部下载脚本 无需
中文等非 ASCII 文件名下载 响应返回 500,无法预览 返回 200;ASCII fallback + UTF-8 filename* 使用中文路径的 Desktop / Web 用户 无需,恢复原本失败的场景
文件路径解析与响应字节 由 workspace 解析并返回原文件 不变 所有本地下载调用方 无需

受影响模块:packages/kap-server 的文件下载路由。

验证:

  • packages/kap-server/test/fs.test.ts:66 个用例通过,包含新增中文 PNG 回归。
  • packages/kap-server typecheck 通过。
  • 仓库 lint 与 kap-server 全量测试结果见最终 CI / 本地回执。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • 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.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Requested by qer via Mira.

@changeset-bot

changeset-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f20b50d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T22:17:46.125450Z f20b50d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 30, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@f20b50d
npx https://pkg.pr.new/@moonshot-ai/kimi-code@f20b50d

commit: f20b50d

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

真实 Windows Desktop 前后验证已完成:同一会话、同一 分析数据/stat/趋势图_20260929_20261028.png 与同一张图片。

  • BEFORE a2afdbc:UI / 独立 GET 均为 500,错误为 ERR_INVALID_CHAR + content-disposition,右侧显示「无法读取这个文件」。
  • AFTER f20b50d:UI / 独立 GET 均为 200、image/png,图片实际显示(naturalWidth=900、naturalHeight=600),下载字节 SHA256 与原图一致,响应头包含 ASCII fallback 与 UTF-8 filename*。

BEFORE / AFTER

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant