Fix invalid and oversized table header colspans - #2277
Open
SkanderBog wants to merge 1 commit into
Open
SkanderBog wants to merge 1 commit into
SkanderBog wants to merge 1 commit into
Conversation
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.
Summary
A header such as
<th colspan="">Product</th>currently raises during extraction, soextract_tables()drops the entire table. Header colspans also bypassCOLSPAN_LIMIT: a value of 1001 expands to 1001 header entries even though body spans are capped at 1000.Reuse the existing bounded span parser for explicit
<thead>headers and inferred first-row headers. Invalid and non-positive header spans become 1; spans above 1000 are capped before list expansion. Body span parsing, table scoring, and row traversal keep their existing behavior.This is a small follow-up to the grid fix merged in #2261. Related to #2258 and the open #2268: that proposal overlaps malformed-header handling, but does not cap header spans. This PR is based on current
developand does not replace its grid implementation.List of files changed and why
crawl4ai/table_extraction.py: lift the existing local span parser into a shared private method and use it for both header paths and the existing body grid.tests/test_table_header_spans.py: 34 regression cases covering explicit headers, inferred th/td headers, malformed/missing/non-positive values, the 1000 boundary, oversized spans, and preservation of adjacent tables.How Has This Been Tested?
Python 3.12.14, Linux, Chromium 153.
develop.python -m pytest tests/test_table_header_spans.py tests/test_table_rowspan_grid.py tests/test_table_gfm_compliance.py tests/unit/test_pdf_html_escaping.py -qpython -m pytest tests/regression/test_reg_content.py -q -m "not network"git diff --checkpassed.The full repository test suite was not run. No claim of complete HTML span-parsing conformance is made; this preserves the existing body parser's normalization rules.
Checklist
develop.