Repository navigation
fix(csv): read a line break in a quoted CSV or TSV cell as whitespace, not a literal \n - #4592
Merged
cragwolfe merged 2 commits intoOct 24, 2026
Conversation
…, not a literal \n `DataFrame.to_html()` writes a line break or tab inside a cell as its escape sequence, so a quoted multi-line field reached `Table.text` and `metadata.text_as_html` as `1 Main St\r\nSpringfield` with literal backslashes. Render the table through a formatter for each column so pandas writes the cell text itself (still HTML-escaped), for both partition_csv() and partition_tsv().
…tespace The s3-minio and sftp fixtures for wiki_movie_plots_small.csv recorded the literal `\r\n` and `\n` escapes this change removes from Table text and text_as_html. Regenerate the structured JSON (text, text_as_html and the element_id that hashes the text) and the HTML and markdown fixtures derived from it. Every other field is unchanged.
cragwolfe
approved these changes
Oct 24, 2026
cragwolfe
left a comment
Contributor
There was a problem hiding this comment.
Reviewed commit 8733f95 with GPT Pro, including the complete diff, changed fixtures, surrounding parser/HTML code, and checked-in tests. No actionable correctness, security, performance, compatibility, or material test-coverage findings remain.
The shared formatter preserves literal backslash sequences and HTML escaping while allowing actual cell whitespace to follow the existing normalization path. Both CSV and TSV use it consistently.
Required CI checks pass at this commit. This technical approval is separate from GitHub’s remaining merge requirements. No local tests were run.
(authored by codex)
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
partition_csv()andpartition_tsv()build the table withDataFrame.to_html(). By default pandas writes a line break or tab inside a cell as its escape sequence, so a quoted field that spans lines (RFC 4180 §2.6 allows this) reachesTable.textandmetadata.text_as_htmlwith literal backslashes:pd.read_csv()parses the field correctly; the backslashes appear only atto_html(). A TSV cell with a quoted newline gives'line one\\nline two'the same way.A small
dataframe_to_html()helper incsv.py, used by both partitioners, passes a formatter for each column so pandas writes the cell text itself. HTML escaping is unchanged (x<y & zbecomesx<y & z) and empty cells stay empty.HtmlTablethen folds the real line break into a space, as it does with other whitespace in a cell, sotext_as_htmldoesn't keep the break as a<br>. If you'd rather keep it, we can change that here.Related: open #4373 (from June, now conflicting) replaces the same
to_html()call with its own HTML builder, which would also avoid this; this PR is the smaller change on currentmain. Neighbours: #4574 (cells read as text) and #4376 / #4279 (row boundaries inHtmlTable.text). We found no existing issue for this (searched csv/tsv newline, line break, multiline, escape,to_html).Validation
test_partition_csv_reads_a_line_break_in_a_quoted_cell_as_whitespace_not_an_escape(also covers a tab and HTML escaping of<and&) and the TSV equivalent.pytest test_unstructured/partition/test_csv.py test_unstructured/partition/test_tsv.pyon Python 3.12, pandas 2.3.3: 103 passed, 9 skipped (the skips needtiktoken, not installed) on this branch. Withmain'scsv.pyandtsv.py, 2 failed, 101 passed, 9 skipped; only the two new tests fail.ruff checkandruff format --check(0.15.10) pass on the four changed files.make testormake check.Checklist
enhancement,bug, or an appropriate existing label), or ask a maintainer to apply it. Could a maintainer applybug? We can't set labels from a fork.!in the title and explain impact and migration above. Not a breaking change.Prepared by CyberNative AI LLC, an AI-run company, using AI agents.