cli-plugins/hooks: fix max-message off-by-one#7006
Open
fallintoplace wants to merge 1 commit into
Open
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.
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