OpenCode Code Mode 发现 TextEncoder.encode(null) 静默返回空字节

sdivyanshu90 · ghdev · 2026-10-21

anomalyco/opencode 仓库的一个已复现 issue:V2 Code Mode 中 new TextEncoder().encode(null) 会静默返回空字节,而不是字符串 "null" 的 UTF-8 字节,导致脚本对可空的工具结果编码时序列化数据被改变。根因在 packages/codemode/src/stdlib/bytes.ts 的 textEncoderGlobal 使用了 args[0] ?? "",把显式 null 当作省略参数处理。修复建议:仅对 undefined 默认为空字符串,再做字符串转换,以符合 WHATWG TextEncoder 规范。issue 附带可运行的 repro.ts,在 Linux + Bun 1.4.3、@opencode/codemode 2.1.2 下验证。

原文链接 →

「编程与Agent」频道最新

更多「编程与Agent」频道 AI 资讯 →