fix: pad short rows in SetRows to the number of columns

SetRows stored rows with fewer cells than the header unchanged, so short
rows rendered fmt's %!s(MISSING) verb and an empty row combined with a
first-column formatter panicked on vals[0]. Pad short rows to the column
count, mirroring AddRow's documented behavior of rendering missing cells
as empty.
This commit is contained in:
dualfroz committed 2026-09-04 09:47:25 +02:00
1 parent c86829d169
commit dc9063405a
3 files changed
+119 -2

No files matched your search

+8 -2
View File
@@ -238,9 +238,15 @@ func (t *table) SetRows(rows [][]string) Table {
headerLength := len(t.header)
for _, row := range rows {
if len(row) > headerLength {
switch {
case len(row) > headerLength:
t.rows = append(t.rows, row[:headerLength])
} else {
case len(row) < headerLength:
// pad short rows so every column is rendered, matching AddRow
padded := make([]string, headerLength)
copy(padded, row)
t.rows = append(t.rows, padded)
default:
t.rows = append(t.rows, row)
}
}