Skip to content

Let CsvHelper read any CSV control and the row accessor a BOM header - #110

Merged
marforon merged 2 commits into
mainfrom
fix_csv
Oct 1, 2026
Merged

marforon merged 2 commits into
mainfrom
fix_csv

Conversation

@marforon

@marforon marforon commented Oct 1, 2026

Copy link
Copy Markdown
Member

CsvHelper::getCsv() called setCsvControl() without arguments, so it could read only comma-separated files and PHP 8.4+ reported the implicit $escape default on every call. A file exported with a UTF-8 BOM left its first column unmapped in AbstractCsvRowAccessor, and a caller had no way to tell a missing column or a blank line from an invalid row.

  • getCsv() takes separator, enclosure and escape with the current defaults and passes them explicitly
  • setHeader() strips a UTF-8 BOM from the first header cell
  • getMissingHeaders() lists the HEADERS the file lacks, isEmpty() detects a blank line read as [null]
  • CHANGELOG entry for 11.7.0

Ronald Márföldi added 2 commits October 1, 2026 18:01
CsvHelper::getCsv() called setCsvControl() without arguments, so it could read only comma-separated
files and PHP 8.4+ reported the implicit $escape default on every call. A file exported with a UTF-8
BOM left its first column unmapped in AbstractCsvRowAccessor, and a caller had no way to tell a
missing column or a blank line from an invalid row.

- getCsv() takes separator, enclosure and escape with the current defaults and passes them explicitly
- setHeader() strips a UTF-8 BOM from the first header cell
- getMissingHeaders() lists the HEADERS the file lacks, isEmpty() detects a blank line read as [null]
- CHANGELOG entry for 11.7.0
A BOM in front of an enclosure keeps fgetcsv() from recognising a quoted first header, so a file
exported with a BOM and quoted headers (PowerShell Export-Csv, LibreOffice "Quote all text cells")
still left its first column unmapped: the parsed cell kept its quotes once the BOM was cut off.

- readHeaders() rewinds, reads three bytes and rewinds again unless they are the BOM, then parses
- the getCsv() test passes a custom enclosure, so dropping it from setCsvControl() fails the test
@marforon
marforon merged commit 5e2d241 into main Oct 1, 2026
2 checks passed
@marforon
marforon deleted the fix_csv branch October 1, 2026 20:15
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