fix(refs): CJK 标签导致 /api/refs/<id>/content 断连 (curl 52)#117
Merged
Conversation
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。
🤖 bot-review (comment-only · phase 1)Diff: Red-line checks:
Needs human review — these paths are not eligible for future 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 |
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.
症状
scott 在 file preview issue thread 里报的:
GET /api/refs/ref_c81a7d元数据正常,size_hint=12225GET /api/refs/ref_c81a7d/content空返回,curl code 52(连接被关)根因
Python
http.server的send_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 决定要不要做