From b17a0ea7960a9888e0506a37a93ce14f0135bbc6 Mon Sep 17 00:00:00 2001 From: BaaRai <130491490+BaaRai@users.noreply.github.com> Date: Tue, 10 Nov 2026 15:07:37 +0100 Subject: [PATCH] notify: report hidden asset count in overflow suffix assetLine appended "and N more" with N = len(assets), the total, instead of the number of assets left out. With 5 assets and a limit of 2 it read "a, b and 5 more"; it now reads "a, b and 3 more". Fix the test that pinned the old value and add an 8-assets/limit-3 case. --- notify/render.go | 4 ++-- notify/render_test.go | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/notify/render.go b/notify/render.go index f88b6f5..7d56537 100644 --- a/notify/render.go +++ b/notify/render.go @@ -149,7 +149,7 @@ func byteSize(s string) int { return len(s) } func runeSize(s string) int { return utf8.RuneCountInString(s) } // assetLine renders an asset list into one line of display text; when there are -// more than limit assets, the rest are omitted and the total is noted. A +// more than limit assets, the rest are omitted and their count is noted. A // vulnerability can be anchored to dozens of assets, and listing them all would // blow up the message. func assetLine(assets []string, limit int) string { @@ -159,7 +159,7 @@ func assetLine(assets []string, limit int) string { if limit <= 0 || len(assets) <= limit { return strings.Join(assets, ", ") } - return strings.Join(assets[:limit], ", ") + " and " + itoa(len(assets)) + " more" + return strings.Join(assets[:limit], ", ") + " and " + itoa(len(assets)-limit) + " more" } // itoa is a short alias for strconv.Itoa, used only for assembling display text, diff --git a/notify/render_test.go b/notify/render_test.go index 66f0eb9..26d8eeb 100644 --- a/notify/render_test.go +++ b/notify/render_test.go @@ -113,11 +113,13 @@ func TestAssetLineOmitsExcess(t *testing.T) { if got := assetLine([]string{"a", "b"}, 3); got != "a, b" { t.Fatalf("within the limit everything should be listed, got %q", got) } - // Over the limit the total must be noted, otherwise readers cannot tell how - // many assets were left out. - got := assetLine([]string{"a", "b", "c", "d", "e"}, 2) - if !strings.Contains(got, "and 5 more") { - t.Fatalf("the total of 5 should be noted, got %q", got) + // Over the limit the number of omitted assets must be noted, otherwise + // readers cannot tell how many assets were left out. + if got := assetLine([]string{"a", "b", "c", "d", "e"}, 2); got != "a, b and 3 more" { + t.Fatalf("5 assets with limit 2 should note the 3 omitted, got %q", got) + } + if got := assetLine([]string{"a", "b", "c", "d", "e", "f", "g", "h"}, 3); got != "a, b, c and 5 more" { + t.Fatalf("8 assets with limit 3 should note the 5 omitted, got %q", got) } }