Skip to content

Do not crash padding an empty table - #447

Open
eeshsaxena wants to merge 1 commit into
Alir3z4:masterfrom
eeshsaxena:pad-tables-empty-guard
Open

Do not crash padding an empty table#447
eeshsaxena wants to merge 1 commit into
Alir3z4:masterfrom
eeshsaxena:pad-tables-empty-guard

Conversation

@eeshsaxena

Copy link
Copy Markdown

pad_tables_in_text crashes with IndexError on an empty table block:

from html2text import config
from html2text.utils import pad_tables_in_text
m = config.TABLE_MARKER_FOR_PAD
pad_tables_in_text(f"{m}\n{m}\n")   # IndexError: list index out of range

When the closing marker is reached the buffered table lines are handed to reformat_table, which reads lines[0] for the column widths. Two markers with nothing between them leave that buffer empty, so it indexes an empty list. Added an early return for the no-lines case, plus a test.

pad_tables_in_text reformats each table block when it hits the closing
marker. Two markers with nothing between them (an empty table) leave the
buffer empty, and reformat_table then read lines[0] and raised
IndexError. Return early when there are no lines.
@eeshsaxena

Copy link
Copy Markdown
Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Do not crash padding an empty table), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining html2text!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant