fix: Read 工具支持非 UTF-8 编码文件(GBK/GB18030 等)#50
Draft
lloydzhou wants to merge 1 commit into
Draft
Conversation
读取 GBK 等非 UTF-8 编码文件时,原始字节直接进入 conversation 并提交 LLM API,导致请求报错。四个实现版本的 Read 工具均缺失编码处理。 修复方案(四版本统一): - 检测文件编码(file -bi),非 UTF-8 时用 iconv 转码(GB18030 兼容 GBK) - 转码失败 fallback 到 sanitize_utf8(保证 JSON 序列化不破坏) - bash: 新增 util_iconv_if_needed 函数,tool_read 调用之 - go: toolRead 增加 utf8.Valid 检测 + iconvToUTF8 辅助函数 - rust: read() 改用 fs::read 读字节 + iconv_to_utf8 方法 - c: 新增 util_iconv_if_needed,tool_read 读取后调用 新增测试: test_read_gbk_encoding 验证 GBK 文件转码为 UTF-8
lloydzhou
marked this pull request as draft
June 17, 2026 12:58
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.
读取 GBK 等非 UTF-8 编码文件时,原始字节直接进入 conversation 并提交
LLM API,导致请求报错。四个实现版本的 Read 工具均缺失编码处理。
修复方案(四版本统一):
新增测试: test_read_gbk_encoding 验证 GBK 文件转码为 UTF-8