From f7b26e0593b81b7f9e63aebe9d9d40e97baef99d Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Wed, 9 Oct 2024 12:03:33 +0530 Subject: [PATCH] Fix panic with footer columns less than header columns Adopted from https://github.com/olekukonko/tablewriter/pull/228 --- table.go | 2 +- table_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/table.go b/table.go index bc5567f..07dc516 100644 --- a/table.go +++ b/table.go @@ -692,7 +692,7 @@ func (t *Table) printFooter() { max := t.rs[footerRowIdx] // Print Footer - for i := 0; i < (len(t.cs) - len(t.footers)); i++ { + for len(t.cs)-len(t.footers) > 0 { lines := t.parseDimension(" ", len(t.footers), footerRowIdx) t.footers = append(t.footers, lines) } diff --git a/table_test.go b/table_test.go index f100731..2f1aec3 100644 --- a/table_test.go +++ b/table_test.go @@ -1309,13 +1309,13 @@ func TestLessFooterColumnsThanHeaders(t *testing.T) { data = [][]string{ {"1", "2", "3"}, } - footer = []string{"a", "b"} + footer = []string{"a"} want = `+---+---+---+ | A | B | C | +---+---+---+ | 1 | 2 | 3 | +---+---+---+ -| A | B | | +| A | | | +---+---+---+ ` )