cli-plugins/hooks: max-message enforcement is off by one
还没有人认领这个 Issue。
评估
调研方向
从 cli-plugins/hooks/template.go 的第 43 行和第 46 行开始,使用 issue 中的 11 行复现代码检查 hooks.ParseTemplate()。添加一个回归测试,表明 10 个换行符会被拒绝,而处于 10 条消息限制以内的输出仍然有效;完成的标准是没有额外的行被合并到最终消息中。
由索引模型根据 Issue 内容生成。
描述
Description
cli-plugins/hooks.ParseTemplate() currently enforces maxMessages = 10 by counting newline characters and rejecting only when strings.Count(out, "\n") > maxMessages, then returning strings.SplitN(out, "\n", maxMessages).
That makes the limit off by one:
- a template that renders to 10 newline characters actually contains 11 messages
- that output is currently accepted instead of rejected
SplitN(..., 10)then merges the extra line into the last returned element, so the final "message" can still contain an embedded newline
This means the "maximum 10 messages" guard can be bypassed by one extra rendered line.
Reproduce
- Use the current
masterbranch. - Call
hooks.ParseTemplate()with output that contains 11 lines, for example:
strings.Repeat("line\n", 10) + "line"
- Observe that no error is returned.
- Observe that the returned slice has length 10, with the last element containing an embedded newline.
The relevant logic is currently in:
cli-plugins/hooks/template.go:43cli-plugins/hooks/template.go:46
Expected behavior
A template that renders to more than 10 messages should be rejected, including the 11-line / 10-newline case.
In other words, the limit should be enforced on the number of returned messages, not just on the number of newline separators.
docker version
N/A for runtime environment. This is a source-level issue in the current master branch checkout.
Observed in local checkout at 9f16882de4.
docker info
N/A for runtime environment. This issue is in template parsing logic and does not depend on daemon configuration.
Additional Info
This looks like it was introduced by b7ab63387a (cli-plugins/hooks: limit maximum number of lines / messages).
I’m happy to send a fix with a regression test if this behavior matches the intended bug report.
- 主要语言
- Go
- 星标
- 6.1k
- 派生
- 2.2k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 43
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/cli 的其他 Issue
-
kind/bug status/0-triage
难度 2/5 1-3 小时 新手友好度 72/100
-
kind/feature status/0-triage
难度 2/5 1-3 小时 新手友好度 70/100
-
kind/bug status/0-triage
难度 2/5 1-3 小时 新手友好度 76/100
-
kind/bug status/0-triage
难度 2/5 1-3 小时 新手友好度 63/100
-
area/ux kind/enhancement
难度 2/5 1-3 小时 新手友好度 78/100
相似的 Issue
-
kind/bug needs-triage
难度 1/5 1 小时以内 新手友好度 72/100
matrixorigin/matrixone#29223 ·
-
needs-acceptance wg/data-plane-networking
难度 2/5 1-3 小时 新手友好度 78/100
vllm-project/semantic-router#4024 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
alexgorbatchev/dotfiles#107 ·
-
难度 1/5 1 小时以内 新手友好度 84/100