Skip to content

fix(refs): CJK 标签导致 /api/refs/<id>/content 断连 (curl 52)#117

Merged
SymbolStar merged 1 commit into
mainfrom
judy/refs-content-fix
Jul 15, 2026
Merged

fix(refs): CJK 标签导致 /api/refs/<id>/content 断连 (curl 52)#117
SymbolStar merged 1 commit into
mainfrom
judy/refs-content-fix

Conversation

@SymbolStar

Copy link
Copy Markdown
Owner

症状

scott 在 file preview issue thread 里报的:

  • GET /api/refs/ref_c81a7d 元数据正常,size_hint=12225
  • GET /api/refs/ref_c81a7d/content 空返回,curl code 52(连接被关)
  • 前端 chip 一直转圈

根因

Python http.serversend_header 只接受 latin-1。这个 ref 的 label 是 SWAT-使用指南.md,写 X-Ref-Label 时抛 UnicodeEncodeError,BaseHTTPRequestHandler 直接把连接关掉——curl 看到就是 exit 52。所有 CJK / emoji / 任何非 latin-1 label 都会中招。

修复

  • _refs_get_content:对 X-Ref-Label / X-Ref-Source-Agent 做 latin-1 探测,非 ASCII/latin-1 的值 percent-encode 兜底
  • 新增回归测试 test_http_content_cjk_label_does_not_crash:CJK 文件名跑完整 round trip,断言内容正常返回且 header 是 percent-encoded

测试

tests/test_refs.py 全绿(36 passed)。

备注

scott 报的另外两件事跟这个不是同一个 bug:

  • /file /raw /download /preview 全 404:这是本来就不存在的路径,唯一正规入口就是 /api/refs/<id>/content
  • [[<root>/…]] 报 "unknown root":v0.8 refs 是 registry,[[milk/…]] 那种 root 映射本来就没实现,需要另开 issue 决定要不要做

http.server 的 send_header 只允许 latin-1 header 值。ref 的 label /
source_agent 里带中文时,写 X-Ref-Label 会抛 UnicodeEncodeError,
连接直接被关掉——前端表现为 chip 一直转圈、curl 报 code 52 空返回。

修复:对 X-Ref-Label / X-Ref-Source-Agent 做 latin-1 探测,非
ASCII/latin-1 内容用 percent-encode 兜底再塞进 header。回归测试
用 CJK 文件名跑一遍 round trip。
@github-actions

Copy link
Copy Markdown

🤖 bot-review (comment-only · phase 1)

Diff: 2 files changed, 33 insertions(+), 2 deletions(-) @ 89154ed

Red-line checks:

  • ✅ A-7.5: no new 'forbidden' code in xiaof

Needs human review — these paths are not eligible for future auto-approve:

  • server.py (HTTP routes / handler — never auto-approve)

Phase 2: auto-approve + auto-merge fire only when red-lines are clean, author is internal, and no needs-human path is touched. Block with no-auto-merge label or [no-auto-merge] in title.

@SymbolStar
SymbolStar merged commit ef38c2a into main Jul 15, 2026
7 checks passed
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