Skip to content

cli-plugins/hooks: fix max-message off-by-one#7006

Open
fallintoplace wants to merge 1 commit into
docker:masterfrom
fallintoplace:7005-hook-template-max-messages
Open

cli-plugins/hooks: fix max-message off-by-one#7006
fallintoplace wants to merge 1 commit into
docker:masterfrom
fallintoplace:7005-hook-template-max-messages

Conversation

@fallintoplace
Copy link
Copy Markdown

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") > maxMessages and then returns strings.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/hooks via a temporary GOPATH layout rooted at this checkout

@fallintoplace fallintoplace marked this pull request as ready for review May 25, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli-plugins/hooks: max-message enforcement is off by one

2 participants