cli-plugins/hooks: fix max-message off-by-one#7006
Conversation
|
Thank you for contributing! It looks like your commit message is missing a DCO sign-off, We require all commit messages to have a There is no need to open a new pull request, but to fix this (and make CI pass), Unfortunately, it's not possible to do so through GitHub's web UI, so this needs You can find some instructions in the output of the DCO check (which can be found Steps to do so "roughly" come down to:
Let me know if you need help or more detailed instructions! |
|
@thaJeztah Thank you. I will check later today. |
Signed-off-by: Minh Vu <vuhoangminh97@gmail.com>
a7f368f to
1ce191f
Compare
Fixes #7005
What changed
This updates
cli-plugins/hooks.ParseTemplate()to enforce the 10-message limit on the actual number of rendered messages instead of on the number of newline separators alone.It also adds a regression test for the 11-line case.
Why it changed
The current implementation rejects only when
strings.Count(out, "\n") > maxMessagesand then returnsstrings.SplitN(out, "\n", maxMessages).That makes the guard off by one: output with 10 newline characters contains 11 messages, but is still accepted. The extra rendered line is then folded into the last returned element.
Impact
Templates that render to more than 10 messages are now rejected consistently, including the 11-line / 10-newline case.
Valid templates keep the existing split behavior.
Root cause
The limit check counted separators instead of messages.
Validation
GOPATH=$(mktemp -d) GO111MODULE=off go test github.com/docker/cli/cli-plugins/hooksvia a temporary GOPATH layout rooted at this checkout