Skip to content

fix(xlsx): escape pipe characters in table cells - #2437

Open
Soroush Ahmadi (soroush5) wants to merge 4 commits into
microsoft:mainfrom
soroush5:fix/xlsx-table-pipe-escape
Open

fix(xlsx): escape pipe characters in table cells#2437
Soroush Ahmadi (soroush5) wants to merge 4 commits into
microsoft:mainfrom
soroush5:fix/xlsx-table-pipe-escape

Conversation

@soroush5

Copy link
Copy Markdown

Fixes #2436.

A | in an Excel cell or header is data, not a column separator. This reuses the CSV converter's escaping (_escape_table_cell, including backslash handling) for both the XLSX and XLS converters, so Excel tables behave like CSV tables. Non-string values (numbers, dates, NaN) pass through untouched.

Tests: new tests/test_xlsx_tables.py (4 tests, failed before, pass after). Full suite: 534 passed + 160 vector tests, no regressions. black --check and git diff --check clean.

A literal | in a cell value or header is data, not a column
separator. Without escaping, converted rows gain phantom columns
and the Markdown table is corrupt. Reuses the CSV converter's
escaping so Excel tables behave like CSV tables.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The OCR XLSX converter remains affected, and the new XLS test relies on an undeclared dependency.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Escapes Markdown-significant pipes in Excel tables.

Changes:

  • Reuses CSV cell escaping for XLSX/XLS values and headers.
  • Adds regression tests for pipes and backslashes.
File summaries
File Description
_xlsx_converter.py Escapes spreadsheet table cells and headers.
test_xlsx_tables.py Adds XLSX/XLS escaping tests.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

for s in sheets:
md_content += f"## {s}\n"
html_content = sheets[s].to_html(index=False)
html_content = _escape_sheet(sheets[s]).to_html(index=False)
Comment on lines +23 to +24
def _xls_bytes(rows: list) -> bytes:
import xlwt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test needs to be rewritten to not depend on any new packages.

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.

XLSX/XLS: pipe characters in cells break Markdown tables

3 participants