fix(csv): escape pipes and newlines in CSV cells#1816
Open
Bojun-Vvibe wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(csv): escape pipes and newlines in CSV cells#1816Bojun-Vvibe wants to merge 1 commit intomicrosoft:mainfrom
Bojun-Vvibe wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@Bojun-Vvibe please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Repo: microsoft/markitdown (⭐ 113363)
Type: bugfix
Files changed: 1
Lines: +11/-5
What
The CSV converter builds a GitHub-flavored markdown table by joining raw CSV cell values with
|. When a cell contains an unescaped|character or an embedded newline (both legal in quoted CSV fields), the emitted markdown table breaks: columns shift, rows split, and downstream markdown renderers misalign the table. This change introduces anescape_cellhelper that escapes backslashes and pipes, and collapses CR/LF sequences to spaces, before the values are joined into the table.Why
CSV files frequently contain free-text cells with punctuation or multi-line values (addresses, descriptions, log entries). Producing malformed markdown for them is a correctness bug in a lossy direction — users won't notice until they render or parse the markdown downstream. The fix is local to the converter, handles header and data rows symmetrically, and follows the standard markdown table escaping convention (
\|).Testing
a|bpreviously produced| a|b |(2 visible columns); now produces| a\|b |(1 column, as intended)."line1\nline2"previously split the row in two; it now renders asline1 line2on a single row.Risk
Low — change is confined to one converter's output formatting; escaping is the markdown-standard convention and only activates on characters that otherwise corrupt the table.