Skip to content

Commit

Permalink
Merge pull request #2140 from midichef/html_empty_table
Browse files Browse the repository at this point in the history
[html] prevent error when parsing an empty table
  • Loading branch information
anjakefala authored Nov 28, 2023
2 parents a06b3f1 + 7fde6e0 commit 35cdf48
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tests/golden/pull2140.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name rows cols id classes
table_0 0 0 test_empty
links 0 5
2 changes: 2 additions & 0 deletions tests/pull2140.vdj
Original file line number Diff line number Diff line change
@@ -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}
7 changes: 5 additions & 2 deletions visidata/loaders/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 35cdf48

Please # to comment.