fix(user-input-fold): 修复嵌套与波浪号代码块的定界符解析,防止折叠预览泄漏未闭合 fence - #336
Open
wswsadadbaba123 wants to merge 1 commit into
Open
fix(user-input-fold): 修复嵌套与波浪号代码块的定界符解析,防止折叠预览泄漏未闭合 fence#336wswsadadbaba123 wants to merge 1 commit into
wswsadadbaba123 wants to merge 1 commit into
Conversation
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.
Problem
extensions/user-input-fold的parseSegments()使用硬编码正则匹配代码块定界符:FENCE_CLOSE接受任意 ≥3 个反引号的行,违反 CommonMark §4.5(N 个反引号开起的代码块只能由 ≥N 个反引号闭合)。粘贴包含内部 ``` 代码块的```` 模板(如 prompt 模板)时,外层代码块被提前闭合,后续内容误判为 Prose,折叠输出泄漏未闭合的````markdown,导致 TUI 中折叠标记 `… folded` 之后的所有终端消息排版被吞噬进未闭合代码块。FENCE_OPEN仅匹配反引号,波浪号(~~~)代码块完全不被识别,被整体当作普通段落截取,折叠时同样泄漏未闭合代码块。受影响对象:粘贴长 Markdown(嵌套 fence 或波浪号 fence)并触发折叠的 TUI 用户。模型可见 Context 与 Session 原始记录不受影响(本扩展仅改渲染层)。
Value
Approach
在 extensions/user-input-fold/index.ts 中:
openFence()解析开起 fence 的字符(`或~)与长度 N(并按规范拒绝 info string 含反引号的反引号 fence);新增isCloseFence()要求闭合 fence 与开起 fence 字符相同且长度 ≥ N。内部 ``` 不再提前闭合```` 块,反引号与波浪号互不闭合。foldUserMessage不变式不变——输入不可变、确定性输出、模型接收完整原文。测试更新:原有一个测试固化了"未闭合 fence 泄漏"的 bug 行为,改为断言合成闭合 fence;新增 4 个回归测试(嵌套 fence、更长闭合 fence、波浪号 fence、反引号/波浪号互不闭合)。
Validation
本机未安装 bun(
bun不在 PATH),以下均以package.json中对应脚本的底层 node 命令等价执行:node --test tests/extensions/user-input-fold/index.test.ts:25/25 通过(含 4 个新增回归测试);tsc --noEmit(typecheck):通过;biome lint .:通过;biome format(两个改动文件):通过;node scripts/check-config-contract.mjs/node scripts/check-discipline-ledger.mjs:通过;+ 内部 ``` 场景):修复前泄漏未闭合 `markdown且内容误判为 Prose;修复后正确输出闭合的 ```` ```` ```` 配对与… folded 18 lines` 标记;node scripts/run-tests.mjs:1117 个 node 测试中 27 个失败,全部为预先存在的 Windows 环境问题(git-info 测试用#!/bin/shstub +:PATH 分隔符导致挂起、symlink 权限、taskkill 时序抖动),已通过 stash 对照确认在干净 HEAD 上同样失败,与本 PR 无关;vitest(file-search)28 过 2 败,同样经 stash 对照确认与 HEAD 一致。未运行:
bun run check原样(bun 未安装);建议 CI(Linux)完整跑一遍作为最终仲裁。Impact
registerMarkdownTransformer仅改渲染层,模型接收的原始文本不变。本次提交修复了问题 #334 感谢@hasak21