fix(cli): reject malformed terminal sequences#5305
Conversation
|
@qwen-code /triage |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Hi @tt-a1i, thanks for the PR! The fix itself looks focused and reasonable — just the OSC parser tightening the code/payload boundary. 👍
However, the PR body doesn't follow the pull request template. The template requires these headings:
## What this PR does## Why it's needed## Reviewer Test Plan(with How to verify, Evidence (Before & After), Tested on)## Risk & Scope## Linked Issues<details>Chinese translation section
Your PR uses ## Summary, ## Test plan, ## Demo, and ## AI Assistance Disclosure instead, and is missing the Reviewer Test Plan, Risk & Scope, Linked Issues sections, and the Chinese translation.
Could you update the PR description to match the template? This helps reviewers (especially maintainers evaluating cross-repo PRs) quickly understand motivation, verify the fix, and assess risk. Once updated, the triage can continue.
中文说明
你好 @tt-a1i,感谢提交 PR!修复本身很聚焦且合理 —— 收紧 OSC 解析器中 code/payload 的分隔符校验。👍
但 PR 正文没有按照 PR 模板 的格式来写。模板要求的标题包括:
## What this PR does(做了什么)## Why it's needed(为什么需要)## Reviewer Test Plan(审阅者测试计划,含 How to verify、Evidence (Before & After)、Tested on)## Risk & Scope(风险与范围)## Linked Issues(关联 Issue)<details>中文翻译
你的 PR 使用了 ## Summary、## Test plan、## Demo 和 ## AI Assistance Disclosure 这些标题,缺少 Reviewer Test Plan、Risk & Scope、Linked Issues 等必填部分,以及中文翻译。
能否按照模板更新一下 PR 描述?这能帮助审阅者(特别是评估外部 PR 的维护者)快速理解动机、验证修复效果和评估风险。更新后 triage 会继续进行。
— Qwen Code · qwen3.7-max
Maintainer verification — local build + before/after parser harnessVerified 1. Unit tests / typecheck / lint (PR code)
2. Before/after adversarial corpus (23 inputs through both versions)
End-to-end gate, headline case: Result: 6/6 malformed cases fixed, 11/11 valid preserved, 0 regressions. Notes for the merge decision
VerdictCorrect, focused, and regression-free from my testing. ✅ No code concerns. The only outstanding item is the triage bot's PR-template formatting request (process, not code). Verified by maintainer @wenshao: local unit suites + a before/after harness running the compiled parser from both 中文版(点击展开)维护者验证 —— 本地构建 + 前后对比解析器测试在 macOS(Darwin arm64,Node v22.22.2)上,针对 1. 单元测试 / 类型检查 / lint(PR 代码)
2. 前后对比对抗性语料(23 个输入分别过两个版本)
端到端门控,头号用例: 结论:6/6 畸形用例修复,11/11 合法用例保留,0 回归。 供合并决策参考
结论从我的测试看:正确、聚焦、无回归。✅ 代码层面无顾虑。唯一未决项是 triage bot 对 PR 模板格式的要求(流程问题,非代码问题)。 维护者 @wenshao 验证:本地单元测试套件 + 一个前后对比 harness(分别从 |
|
@qwen-code /triage |
|
Thanks for the PR! Template looks good ✓ On direction: this is a clean correctness and security fix — the OSC parser was accepting malformed sequences where the numeric code wasn't followed by On approach: minimal and focused — 2 files, +8/-3. The fix is exactly one condition change ( Moving on to code review. 🔍 中文说明感谢贡献! 模板完整 ✓ 方向:这是一个干净的正确性和安全修复——OSC 解析器此前接受了数字代码后未跟 方案:最小且聚焦——2 个文件,+8/-3。修复就是一个条件的变更( 进入代码审查 🔍 — Qwen Code · qwen3.7-max |
Code reviewThe fix is a single condition change in The stale comment No correctness bugs, no security holes, no regressions. The fix is structurally safe: every valid allowlisted OSC sequence has No blockers found. TestingUnit tests (PR code)
Before/after parser verificationVitest (PR code)2 malformed cases fixed, all valid cases preserved, 0 regressions. 中文说明代码审查修复是 过时注释 无正确性 bug、无安全漏洞、无回归。修复在结构上是安全的:每个合法的白名单 OSC 序列在代码后都有 未发现阻塞项。 测试单元测试(PR 代码)
修改前后解析器验证2 个非法用例已修复,所有合法用例保留,0 回归。 — Qwen Code · qwen3.7-max |
|
This is a textbook bug fix — one condition, one file, one bug. The parser had a gap between its documented contract ( My independent proposal would have been identical: add The before/after testing confirms: malformed sequences ( The security angle is real too: since hooks control Approving. ✅ 中文说明这是一个教科书式的 bug 修复——一个条件、一个文件、一个 bug。解析器的文档化契约( 我的独立方案完全相同:在代码读取循环之后添加 修改前后测试确认:非法序列( 安全角度也是真实的:由于 hook 控制 批准。✅ — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
What this PR does
Tightens the
terminalSequenceOSC parser so it rejects malformed input where the numeric OSC code is not immediately followed by a;separator. Previously, after reading the numeric code the parser began scanning for a terminator straight away, so an input likeESC]9oopsBELwas accepted as a valid OSC 9 sequence (withoopsmistaken for the payload andBELas the terminator). The parser now requires a;after the code before the payload; inputs such asESC]9oopsBEL,ESC]9BEL, andESC]9ESC\are rejected.The allowed OSC code list (0, 1, 2, 9, 99, 777) is unchanged — this only tightens the boundary between the numeric code and the payload.
Why it's needed
The parser's own documentation states the expected shape is
ESC ] <code> ; <payload> <terminator>and that the code should be followed by;or a terminator. But it accepted OSC input where the numeric code was followed by arbitrary text, so a malformed sequence likeESC]9oopsBELwas passed through to the terminal as an allowed OSC 9 notification instead of being rejected. This fix makes the parser enforce the documented shape, in line with its "reject invalid input entirely — no partial stripping" policy.Reviewer Test Plan
How to verify
Repro (before this change): a hook-provided
terminalSequencesuch asESC]9oopsBELwas parsed as a valid OSC 9 sequence and emitted to the terminal. Expected: it should be rejected (parser returnsnull). Observed after the fix: the malformed sequence is rejected, while well-formed sequences (e.g.ESC]9;hiBEL) continue to parse.Verification commands (from
packages/cli):npx vitest run src/utils/terminalSequence.test.tsnpm run typecheck --workspace=packages/clinpm run lint -- --fix packages/cli/src/utils/terminalSequence.ts packages/cli/src/utils/terminalSequence.test.tsnpx prettier --check packages/cli/src/utils/terminalSequence.ts packages/cli/src/utils/terminalSequence.test.tsgit diff --checkEvidence (Before & After)
N/A — non-visible logic fix; covered by the unit tests above.
Tested on
✅ tested ·⚠️ not tested · N/A
Environment (optional)
Unit tests only (npm workspaces).
Risk & Scope
parseOscSequence. The only behavior change is that OSC codes not followed by;are now rejected.;) are now rejected, which is the intended bug fix.Linked Issues
Fixes #5304
中文说明
此 PR 的作用
收紧
terminalSequence的 OSC 解析器,使其拒绝数字 OSC 代码后面没有紧跟;分隔符的非法输入。此前解析器读取完数字代码后会立即开始扫描终止符,因此像ESC]9oopsBEL这样的输入会被当作合法的 OSC 9 序列接受(oops被误当作 payload,BEL被当作终止符)。现在解析器要求代码之后、payload 之前必须有;;诸如ESC]9oopsBEL、ESC]9BEL、ESC]9ESC\等输入都会被拒绝。允许的 OSC 代码列表(0、1、2、9、99、777)保持不变——本次改动只收紧数字代码与 payload 之间的边界。
为什么需要
解析器自身的文档说明期望的形态是
ESC ] <code> ; <payload> <terminator>,并说明代码后应跟随;或终止符。但它却接受了数字代码后跟随任意文本的 OSC 输入,因此像ESC]9oopsBEL这样的非法序列会作为合法的 OSC 9 通知被透传到终端,而不是被拒绝。此修复让解析器强制遵循其文档化的形态,符合其"完全拒绝非法输入——不做部分剥离"的策略。审查者测试计划
如何验证
复现(改动前):像
ESC]9oopsBEL这样的钩子提供的terminalSequence会被解析为合法的 OSC 9 序列并发送到终端。预期:应被拒绝(解析器返回null)。修复后观察到:非法序列被拒绝,而格式正确的序列(例如ESC]9;hiBEL)仍能正常解析。验证命令(在
packages/cli下执行):npx vitest run src/utils/terminalSequence.test.tsnpm run typecheck --workspace=packages/clinpm run lint -- --fix packages/cli/src/utils/terminalSequence.ts packages/cli/src/utils/terminalSequence.test.tsnpx prettier --check packages/cli/src/utils/terminalSequence.ts packages/cli/src/utils/terminalSequence.test.tsgit diff --check证据(修改前后对比)
不适用 —— 这是非可视的逻辑修复;已由上述单元测试覆盖。
测试平台
✅ 已测试 ·⚠️ 未测试 · 不适用
环境(可选)
仅单元测试(npm workspaces)。
风险与范围
parseOscSequence中 OSC 代码/payload 的边界检查。唯一的行为变化是:代码后未跟;的 OSC 现在会被拒绝。;)现在会被拒绝,这正是预期的 bug 修复。关联 Issue
Fixes #5304
AI Assistance Disclosure
I used Codex to review the changes, sanity-check the implementation against existing patterns, and help spot potential edge cases.