Skip to content

test(server): cover download filename edge cases - #4790

Merged
wbxl2000 merged 2 commits into
mainfrom
fix/unicode-download-content-disposition
Nov 10, 2026
Merged

wbxl2000 merged 2 commits into
mainfrom
fix/unicode-download-content-disposition

Conversation

@kimi-agent-bot

@kimi-agent-bot kimi-agent-bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

#4563 已修复非 ASCII 文件名导致下载响应头失败的问题,并于 2026-11-10 合入 main(1eb3c537e)。原回归只覆盖一个中文 PNG。本 PR 只补齐边界回归,防止 Desktop / Web 的 PDF 与媒体预览再次受文件名编码问题影响。

本 PR 不重复实现 #4563,也不改变运行时代码。#2286 的同类 sanitize 修复已由 #4563 取代,建议维护者关闭 #2286,避免继续分叉。

Bug Reproduction Steps

  1. 在中文目录中放置文件名包含中文、全角括号、空格或 emoji 的 PDF / PNG。
  2. 通过 /api/v1/sessions/:id/fs/:path:download 下载文件。
  3. 检查状态码、Content-Type、Content-Disposition 和响应字节。
  4. 对引号、反斜杠、CR/LF 文件名重复检查;对普通 ASCII 文件名确认原响应头不变。

Root Cause

#4563 已定位并修复根因:原始非 ASCII 文件名不能直接写入 Node 的 Content-Disposition 响应头。本 PR 处理的是回归覆盖缺口,不引入另一套修复。

Code Changes

将原有单个中文 PNG 用例扩展为同一路由的参数化回归矩阵:

  • 普通 ASCII 文件名保持原有 attachment; filename="...",不添加 filename*。
  • 中文目录 + 中文 PDF,以及中文 PNG + 全角括号 + 空格 + emoji。
  • 引号与反斜杠的转义。
  • CR/LF 不进入普通 filename 参数,原文件名仅以 RFC 5987 编码出现在 filename*。
  • 引号/反斜杠与 CR/LF 两组 POSIX-only fixture 在 win32 上过滤,其余三组保留跨平台覆盖。
  • 每项均断言 HTTP 200、MIME、完整 Content-Disposition 和原始下载字节。

Screenshots / Recordings

同一真实 kap-server 下,Desktop 与 Web 均通过真实 Markdown 文件链接打开中文 PDF 与 PNG。四象限依次为 Desktop PDF、Desktop PNG、Web PDF、Web PNG;PDF 真实渲染,PNG 实际显示,UI 响应字节均与源文件一致。

Desktop / Web 中文 PDF 与 PNG 最终验证

Behavior Changes and Affected Users

None。仅修改 packages/kap-server/test/fs.test.ts;下载路由、路径解析、MIME、文件字节和客户端行为均未改变。

反馈边界:Bug 收敛记录 53825081-cba9-41e9-88a6-2388b086e6fe 同时包含另一种 HTTP 200 错误 envelope 机制。本 PR 不宣称关闭该记录,也不覆盖路径解析或大文件截断问题。

验证:

  • 修复前 0125dbb20 + 同一测试补丁:4 个非 ASCII / 转义用例失败,普通 ASCII 用例通过。
  • 修复后 packages/kap-server/test/fs.test.ts:70/70 通过。
  • 仓库 pnpm typecheck:通过。
  • 仓库 pnpm lint:0 errors;既有 warnings 不属于本 PR。
  • 当前 HEAD fb2de0791 的 CI:16 项成功,test-windows 按既有条件跳过。
  • Codex 对当前 HEAD 零发现,未决 review thread 为 0。
  • Windows 真机:kc 1eb3c537e + kca f54db65b,Desktop 1.3.2 / Electron 43.1.1 与 Chrome Web 使用同一真实 kap-server。Desktop / Web 的中文 PDF 与 PNG 预览 4/4 PASS;PDF 真实渲染,PNG 为 1000×640,UI 实际响应字节与源文件 SHA256 一致,未出现 ERR_INVALID_CHAR。
  • 追加异常 BEFORE:缺失文件仍会以 HTTP 200 返回 JSON envelope。该独立问题由后续双仓修复处理,不属于本测试 PR 的运行时改动。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • 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.

@changeset-bot

changeset-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fb2de07

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T07:50:29.200504Z fb2de07 Manual request
ℹ️ 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 Nov 10, 2026 •

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

commit: fb2de07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56c8eea0e7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kap-server/test/fs.test.ts Resolved
@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: fb2de0791c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000
wbxl2000 merged commit ba4dd7f into main Nov 10, 2026
18 checks passed
@wbxl2000
wbxl2000 deleted the fix/unicode-download-content-disposition branch November 10, 2026 09:02
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.

2 participants