Skip to content

fix: preserve repeated quoted CSV headers without a final newline - #4786

Merged
cragwolfe merged 1 commit into
Unstructured-IO:mainfrom
Afloat16:Afloat16/preserve-quoted-csv-headers-at-eof-20261116
Nov 17, 2026
Merged

cragwolfe merged 1 commit into
Unstructured-IO:mainfrom
Afloat16:Afloat16/preserve-quoted-csv-headers-at-eof-20261116

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The repeated-header restoration added in #4709 misses a complete quoted header when the file has no final newline. For example, a file containing only "name","name" produces name name.1 even though the second label is name.

At the end of a complete peeked line, treat a pending quote as the closing quote of its field. A line without a terminator reaches this check only at EOF: the bounded header peek returns an empty string if its budget is exhausted, rather than returning a truncated prefix. Unclosed quoted fields and multi-line header handling retain their existing guards.

The shared reader fixes CSV and TSV, including escaped quotes within duplicate labels. No read budget, delimiter, field-size limit or data-row behavior changes.

Validation

  • The 27 new cases produce 18 failures and 9 passing controls on the original source.
  • Exercises filename and byte-stream inputs, comma/semicolon/tab separators, duplicate labels, genuine suffixed labels and escaped quotes. Controls cover LF/CRLF endings and incomplete quoted records.
  • A combined fork validation branch runs both changes' regressions against the pinned original source: 27 failures, 12 passing controls. With the final source restored, the regressions plus the existing Prodigy, CSV and TSV suites report 192 passed on Python 3.12.
  • The existing CSV suite includes bounded and prefilled header-peek tests, multi-line header controls and the exhaustive single-line splitter comparison with Python's CSV reader.
  • Repository-configured Ruff check, format check and source-integrity checks pass.
  • Validation run, exact commands and JUnit artifacts.

Checklist

  • User-facing conventional-commit title.
  • Maintainer: please apply the bug category label.

View guided diff

@cragwolfe cragwolfe 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.

Static review of the CSV and TSV change, including table output, chunking, metadata, and serialization: no actionable Critical, High, or Medium defects found.

This fix intentionally changes the public text and HTML for a header-only file with repeated quoted labels and no final newline. For example, name name.1 becomes name name. Consumers that depend on the prior output may see changed serialized values, text-derived IDs, or chunk boundaries. A maintainer should decide whether that compatibility change is acceptable.

I did not run tests or benchmarks. CI remains separate from this review.

(authored by codex)

@cragwolfe
cragwolfe enabled auto-merge November 16, 2026 23:43
@cragwolfe
cragwolfe added this pull request to the merge queue Nov 17, 2026
Merged via the queue into Unstructured-IO:main with commit 08c7eb1 Nov 17, 2026
53 checks passed
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.

2 participants