Bug: underscore auto-escaped to backslash in message pipeline, corrupts Windows paths

在 LobeChat 桌面端“群聊 + 本地系统工具”场景中,消息里包含带下划线的 Windows 路径(如 D:\godot_mcp )时,下划线可能被自动转义成 \_ ,导致 AI 或本地文件工具把反斜杠当成目录分隔符、解析到错误子目录。优先排查消息管道/Markdown 转义是否会改写原始文本

快速结论:在 LobeChat 桌面端“群聊 + 本地系统工具”场景中,消息里包含带下划线的 Windows 路径(如 D:\godot_mcp)时,下划线可能被自动转义成 \_,导致 AI 或本地文件工具把反斜杠当成目录分隔符、解析到错误子目录。优先排查消息管道/Markdown 转义是否会改写原始文本,并先用“去掉下划线”的路径临时规避。

适用环境:Issue 中已确认的环境为 LobeHub Desktop 群聊(Group Chat)+ local-system 工具(listFiles、runCommand);涉及包含下划线的 Windows 路径。Issue 未提供 Python、CUDA、PyTorch、显卡或具体依赖版本信息。

最快修复方案:暂无确认的一步修复方案。Issue 中唯一被验证有效的处理是临时规避:把文件夹名中的下划线去掉(如 godot_mcp 改为 godotmcp),实际使用前建议先在群聊中发一条路径做验证。

注意事项:该 Issue 被标记为 Duplicate 并自动关闭(引用的疑似重复为 #12303),因此社区未在此 Issue 内确认官方修复;Issue 中“Markdown 渲染层转义下划线”只是用户推测的原因,未经官方确认。改名规避会改变实际路径,可能影响依赖原路径的脚本或配置。

问题场景

用户在 LobeHub Desktop 的群聊(Group Chat)中使用 local-system 工具(如 listFiles、runCommand),输入类似 D:\godot_mcp 的 Windows 路径。消息管道会在下划线前自动追加一个反斜杠,AI agent 收到的路径变成 D:\godot\_mcp,从而把添加的反斜杠当成 Windows 目录分隔符,最终解析为“godot 下的子目录 _mcp”,而不是单个名为 godot_mcp 的文件夹。用户因此浪费了 7 轮对话排查。

报错原文

Bug: underscore auto-escaped to backslash in message pipeline, corrupts Windows paths

User inputs D:\godot_mcp. Pipeline adds backslash before underscore.
AI misparses as subdirectory.
Expected: no auto-escape.

1. User inputs path containing underscore in Group Chat, e.g. D:\godot_mcp
2. Message pipeline auto-escapes underscore with preceding backslash
3. AI agent receives D:\godot\_mcp
4. AI interprets the added backslash as Windows directory separator
5. Path resolves to folder godot with subfolder _mcp instead of a single folder named godot_mcp
6. local-system tools (listFiles, runCommand) all read wrong path.

原因分析

可能原因:Markdown 渲染层为避免下划线被解析为斜体(italic)而进行转义,把 _ 转成 \_。按照用户复现描述,该转义似乎也作用于原始文本(raw text),因此在消息到达 AI 之前路径就已被改写。由于 Windows 路径本身以反斜杠作分隔符,新增的 \ 被 AI 与本地文件工具误判为目录层级,导致路径指向错误位置。以上为 Issue 中的推测,官方未确认根因。

环境排查

  • 确认是否为 LobeHub Desktop 的群聊(Group Chat)场景,且启用了 local-system 工具(listFiles、runCommand)。
  • 确认输入路径是否为 Windows 路径且包含下划线。
  • 对比测试:同一路径分别带下划线与不带下划线,观察消息管道输出是否被改写。
  • Issue 未提供 Python、CUDA、PyTorch、显卡及相关依赖版本,无需在此假设。

解决步骤

  1. 在群聊中发送一条含下划线的 Windows 路径,例如 D:\godot_mcp,观察实际传给 AI 的文本是否变成 D:\godot\_mcp。
  2. 若确认被转义,临时规避:把文件夹重命名去掉下划线,例如 godot_mcp 改为 godotmcp,再让 local-system 工具访问该路径。
  3. 改名后重新用 listFiles / runCommand 验证路径是否可正常读取。
  4. 关注原 Issue 所指向的疑似重复 Issue #12303,确认是否存在官方修复或后续方案。

验证方法

重命名后再让 AI 用 local-system 工具读取该路径:若 listFiles 能列出目标文件夹内容、runCommand 能正常执行,说明规避生效;同时确认群聊中该路径不再出现 \_ 形式的转义。

参考来源

lobehub/lobe-chat #14933

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 25863

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注