From bb08e29151ec41838bc1378257eeeca7670ff57f Mon Sep 17 00:00:00 2001 From: 0z5a Date: Sat, 14 Nov 2026 13:46:31 +0100 Subject: [PATCH] fix: use the first column as the default LabelValueTable label LabelValueTable() is documented to use the first column as the label when label_list is None, but the default was the first column name itself, a string. The validation loop then iterated over its characters, so any table whose first column name is longer than one character raised "TableError: Invalid label prefix: .". CliTable.LabelValueTable() falls back to the same default when the template has no Key values. Wrap the default in a list and add a test with multi-character column names. --- tests/texttable_test.py | 10 ++++++++++ textfsm/texttable.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/texttable_test.py b/tests/texttable_test.py index 342c160..1e31aa7 100755 --- a/tests/texttable_test.py +++ b/tests/texttable_test.py @@ -543,6 +543,16 @@ def testTableWithLabels(self): t.LabelValueTable(['c', 'a'])) self.assertRaises(texttable.TableError, t.LabelValueTable, ['a', 'z']) + def testTableWithLabelsDefaultMultiCharHeader(self): + t = texttable.TextTable() + t.header = ('Interface', 'Status') + t.Append(('ge-0/0/0', 'up')) + t.Append(('ge-0/0/1', 'down')) + self.assertEqual( + '# LABEL Interface\nge-0/0/0.Status up\nge-0/0/1.Status down\n', + t.LabelValueTable()) + self.assertEqual(t.LabelValueTable(['Interface']), t.LabelValueTable()) + def testTextJustify(self): t = texttable.TextTable() self.assertEqual([' a '], t._TextJustify('a', 6)) diff --git a/textfsm/texttable.py b/textfsm/texttable.py index 71450a0..e136814 100755 --- a/textfsm/texttable.py +++ b/textfsm/texttable.py @@ -905,7 +905,7 @@ def LabelValueTable(self, label_list=None): Raises: TableError: If specified label is not a column header of the table. """ - label_list = label_list or self._Header()[0] + label_list = label_list or [self._Header()[0]] # Ensure all labels are valid. for label in label_list: if label not in self._Header():