From 8057154e7cadf40ba0eaaeec290e0a356904600c Mon Sep 17 00:00:00 2001 From: midichef <67946319+midichef@users.noreply.github.com> Date: Sun, 26 Nov 2023 21:23:10 -0800 Subject: [PATCH 1/2] [html] prevent error when parsing an empty table --- visidata/loaders/html.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/visidata/loaders/html.py b/visidata/loaders/html.py index 509727f41..a950dea18 100644 --- a/visidata/loaders/html.py +++ b/visidata/loaders/html.py @@ -154,8 +154,11 @@ def iterload(self): if headers: it = itertools.zip_longest(*headers, fillvalue='') else: - it = list(list(x) for x in self.rows.pop(0)) - it += [''] * (ncols-len(it)) + if len(self.rows) > 0: + it = list(list(x) for x in self.rows.pop(0)) + it += [''] * (ncols-len(it)) + else: + it = [] for colnum, names in enumerate(it): name = '_'.join(str(x) for x in names if x) From 7fde6e0493d63916116c24b04358a1a4f9ab2b77 Mon Sep 17 00:00:00 2001 From: anjakefala Date: Mon, 27 Nov 2023 21:17:08 -0800 Subject: [PATCH 2/2] [tests] add test for loading empty html table --- tests/golden/pull2140.tsv | 3 +++ tests/pull2140.vdj | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 tests/golden/pull2140.tsv create mode 100644 tests/pull2140.vdj diff --git a/tests/golden/pull2140.tsv b/tests/golden/pull2140.tsv new file mode 100644 index 000000000..4c5641188 --- /dev/null +++ b/tests/golden/pull2140.tsv @@ -0,0 +1,3 @@ +name rows cols id classes +table_0 0 0 test_empty +links 0 5 diff --git a/tests/pull2140.vdj b/tests/pull2140.vdj new file mode 100644 index 000000000..b20a78d04 --- /dev/null +++ b/tests/pull2140.vdj @@ -0,0 +1,2 @@ +#!vd -p +{"sheet": null, "col": null, "row": null, "longname": "open-file", "input": "sample_data/empty-table.html", "keystrokes": "o", "comment": null}