Files
cc-web/.planning/file-preview-encoding/task_plan.md
2026-08-07 10:54:08 +08:00

39 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 任务计划:中文文件预览编码兼容
## 目标
修复文件浏览器预览 GBK/GB2312/GB18030 等中文文本时出现替换字符的问题,并保持 UTF-8 与二进制拒绝行为稳定。
## 当前阶段
阶段 5交付
## 阶段
- [x] 定位文件预览读取与渲染链路
- [x] 补充非 UTF-8 中文文件回归测试
- [x] 实现安全的多编码检测与解码
- [x] 运行相关测试与静态检查
- [x] 执行浏览器回归并复核变更
## 交付结果
- 服务端支持 UTF-8、UTF-8/UTF-16 BOM、GB18030兼容 GBK/GB2312
- `/api/fs/read` 返回 `encoding`,前端预览元信息展示识别结果。
- 二进制 415、路径安全、预览大小限制保持不变。
- Trellis 实现与检查代理均未发现明确缺陷。
## 关键决策
- 在服务端解码API 继续返回合法 JSON/Unicode前端无需猜测原始字节编码。
- BOM 优先;无 BOM 时严格验证 UTF-8无效 UTF-8 回退 GB18030。
- 仅对已判定为文本的内容解码,不能放宽二进制文件预览限制。
- API 返回实际识别编码,便于诊断,但前端不依赖该字段。
## 错误记录
| 错误 | 尝试 | 处理 |
|---|---:|---|
| codebase-memory `search_code` 返回 `pattern is required` | 1 | 查阅工具 schema 后改用 `pattern` |
| 计划补丁未命中模板标题 | 1 | 读取真实模板后精确替换 |