internal: fix MaxSizeSubjectsListForLog off-by-one when maxToDisplay is 0

The loop appended before checking the length, so with maxToDisplay=0
one domain leaked into the output before the break check. Reorder so
the length check comes first.

Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
pull/7227/head
Mohammed Al Sahaf 2026-08-30 18:21:59 +03:00
parent 5bdfdeb848
commit d9ca71a718
No known key found for this signature in database
1 changed files with 2 additions and 6 deletions

View File

@ -90,12 +90,8 @@ func TestMaxSizeSubjectsListForLog(t *testing.T) {
"b.com": {},
},
maxToDisplay: 0,
// BUG: When maxToDisplay is 0, code still appends one domain
// because append happens before the break check in the loop.
// Expected behavior: 1 item (just suffix). Actual: 2 items
// (1 leaked domain + suffix).
wantLen: 2,
wantSuffix: true,
wantLen: 1,
wantSuffix: true,
},
{
name: "single subject with max 1",