convert_tables: don't crash on tables with no rows (#63 case 1) - #69
Open
eeshsaxena wants to merge 1 commit into
Open
convert_tables: don't crash on tables with no rows (#63 case 1)#69eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
Conversation
_process_table indexed find_all('tr')[0] before checking whether the table
had any rows, so an empty <table> or an empty <tbody> (ordinary output from
many CMSes) raised IndexError instead of being skipped.
Return early with no data when the table has no rows; convert_tables already
drops empty results, so such tables are simply omitted from the output.
This is case 1 from fhightower#63; the ragged/class-B cases there involve a semantics
decision and are left out of this change.
Author
|
Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Picks off the unambiguous part of #63: an empty table crashes.
_process_tablereadsfind_all('tr')[0]before checking that the table has any rows. An empty<tbody>is ordinary CMS output, so this isn't only an adversarial-input concern.Added an early return of the empty result when there are no rows.
convert_tablesalready drops empty results, so a rowless table is simply omitted (including when it sits next to a real table). Tables with rows are untouched.I deliberately left the ragged/class-B cases from #63 out of this PR since, as you noted there, they need a semantics decision and case 2 overlaps with #64.
Added two tests in
test_html_tables_misc.py(empty table alone, and empty table next to a real one). The empty-table case raisesIndexErroronmainand passes with this change.