Skip to content

Commit faff935

Browse files
madmaxxtmaxymnc
andauthored
fix(docx): handle tables with merged cells causing IndexError (#2813)
* fix(docx): handle tables with merged cells causing IndexError When parsing tables with merged cells, the number of cells in a row can be less than the total number of columns. The code was iterating up to num_cols and accessing row.cells[col_idx], which caused IndexError when col_idx exceeded the actual number of cells in the row. Added bounds check before accessing row.cells to handle merged cell rows. * DCO Remediation Commit for Maxym Tushkov <maxym.nc@gmail.com> I, Maxym Tushkov <maxym.nc@gmail.com>, hereby add my Signed-off-by to this commit: 144047a Signed-off-by: Maxym Tushkov <maxym.nc@gmail.com> --------- Signed-off-by: Maxym Tushkov <maxym.nc@gmail.com> Co-authored-by: Maxym Tushkov <maxym.nc@gmail.com>
1 parent be085c0 commit faff935

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

docling/backend/msword_backend.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,9 @@ def _handle_tables(
13511351
_log.debug(f"Row index {row_idx} with {len(row.cells)} populated cells")
13521352
col_idx = 0
13531353
while col_idx < num_cols:
1354+
# Handle merged cells: row may have fewer cells than num_cols
1355+
if col_idx >= len(row.cells):
1356+
break
13541357
cell: _Cell = row.cells[col_idx]
13551358
_log.debug(
13561359
f" col {col_idx} grid_span {cell.grid_span} grid_cols_before {row.grid_cols_before}"

0 commit comments

Comments
 (0)