cli-plugins/hooks: max-message enforcement is off by one
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at cli-plugins/hooks/template.go lines 43 and 46, and inspect hooks.ParseTemplate() with the 11-line reproduction from the issue. Add a regression test showing that 10 newline characters are rejected while outputs within the 10-message limit remain valid; done means no extra line is merged into the final message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100