Skip to content

fix(csv): skip leading blank lines so they don't wipe the whole table#2137

Open
wajih-rathore wants to merge 1 commit into
microsoft:mainfrom
wajih-rathore:fix-csv-leading-blank-line
Open

fix(csv): skip leading blank lines so they don't wipe the whole table#2137
wajih-rathore wants to merge 1 commit into
microsoft:mainfrom
wajih-rathore:fix-csv-leading-blank-line

Conversation

@wajih-rathore

Copy link
Copy Markdown

Fixes #2136.

A CSV whose first line is blank converts to an all-empty markdown table. Every row comes out as | | and the data is silently lost.

Cause: csv.reader yields [] for the blank first line, so rows[0] is empty. The converter treats rows[0] as the header (column count 0), then truncates every data row with row[: len(rows[0])] -> row[:0], dropping all the cells.

Fix: drop leading empty rows before choosing the header row, so the first real row becomes the header. Added a test fixture with a leading blank line (must_not_include checks the | | empty-cell output no longer appears).

Before:

|  |
|  |
|  |
|  |

After:

| name | age |
| --- | --- |
| bob | 3 |
| alice | 7 |

A CSV whose first line is blank converted to an all-empty markdown table.
csv.reader yields [] for the blank line, so rows[0] had zero columns. That
empty row became the header, and every data row was then truncated with
row[:len(rows[0])] == row[:0], silently dropping all the data.

Skip leading empty rows before choosing the header. Adds a regression test
fixture with a leading blank first line.
@wajih-rathore

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@ericsondea-collab

Copy link
Copy Markdown

clks vksd fs ,fçç,s v s fçdfps s,çdsç,v slkls

@ericsondea-collab

Copy link
Copy Markdown

fsdsm vkmonf smp vç vçs spmmel

@ericsondea-collab

Copy link
Copy Markdown

sdvnsd v msf lms,ldnksnv çsl

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.

CSV with a blank first line converts to an all-empty table (data silently lost)

2 participants