Skip to content

[Bug] 审核页面展开 Collapsible 时 MarkupError 崩溃 / Audit tab crashes with MarkupError when expanding a collapsible #124

@SunYanbox

Description

@SunYanbox

Issue 描述 (Description)

中文
在审核(Audit)标签页中,点击待审核文件的可折叠块展开详情时,应用直接崩溃,并抛出 MarkupError。错误信息提示 “Expected markup value (found '+ getCLISyspromptPrefix({...}), // "You are Claude Code, Anthropic's official CLI..."\n')”,原因为待审核的 diff 内容中包含方括号 [ 字符,被 Textual 的 Static 控件误解析为 Rich 标记语法。

English
When expanding a collapsible file item in the Audit tab, the application crashes with a MarkupError: “Expected markup value (found '+ getCLISyspromptPrefix({...}), // "You are Claude Code, Anthropic's official CLI..."\n')”. The crash occurs because the diff content contains square brackets ([), which the Static widget tries to parse as Rich markup by default.

复现步骤 (Steps to Reproduce)

  1. 在一个项目中创建一次待审核的文件变更(例如编辑一个包含 [key][...] 代码片段的文件)。
  2. 使用 ManualAid 打开该工作区。
  3. 切换到 审核(Audit) 标签页。
  4. 点击包含上述文件的折叠项展开详情。
  5. 应用崩溃。

预期行为 (Expected Behavior)

审核界面应正常展开并显示 diff 内容,不因内容中的特殊字符而崩溃。

实际行为 (Actual Behavior)

应用直接退出,终端显示如下 Traceback 关键部分:

MarkupError: Expected markup value (found '+  ... // "You are Claude Code, ..."\n').
...
File "...\src\console\ui\widgets\audit_tab.py", line 139, in _refresh
    diff_container = Vertical(Static(diff_content), classes="audit-diff")

根本原因 (Root Cause)

  • Static(diff_content) 默认开启 Rich 标记解析(markup=True),当 diff 文本包含 [ 字符时被误认为标记起始符。
  • 同一文件中另外一处 Static(f"[{color}]{result}[/{color}]")result 也可能包含特殊字符,破坏了 Rich 标记结构。

修复方案 (Fix)

修改文件 src/console/ui/widgets/audit_tab.py

  1. 为 diff 内容 Static 禁用标记解析:
    Static(diff_content, markup=False)
  2. 对审核结果消息中的 result 进行转义,并引入 rich.markup.escape
    from rich.markup import escape
    ...
    escaped = escape(result)
    await log.mount(Static(f"[{color}]{escaped}[/{color}]"))

受影响的版本 (Affected Versions)

  • <=v0.4.0

状态 (Status): 已修复并进行简单测试,一段时间后会推送到 GitHub / Fixed and briefly tested; will be pushed to GitHub shortly.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions