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>
This commit is contained in:
Mohammed Al Sahaf committed 2026-10-19 11:19:15 +03:00
1 parent 5bdfdeb848
commit d9ca71a718
1 file changed
+2 -6
+2 -6
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",