Skip to content

Import-DbaCsv - Fix RFC 4180 multiline quoted field handling#10190

Merged
potatoqualitee merged 1 commit intodataplat:developmentfrom
mbentham:fix/import-dbacsv-multiline-rfc4180
Feb 26, 2026
Merged

Import-DbaCsv - Fix RFC 4180 multiline quoted field handling#10190
potatoqualitee merged 1 commit intodataplat:developmentfrom
mbentham:fix/import-dbacsv-multiline-rfc4180

Conversation

@mbentham
Copy link
Contributor

@mbentham mbentham commented Feb 23, 2026

Summary

Fixes two bugs that caused Import-DbaCsv to reject valid CSV files containing multiline quoted fields (permitted by RFC 4180).

  • Pre-validation false rejection (Import-DbaCsv Pre-validation incorrectly rejects valid CSV files with multiline quoted fields #10188): The delimiter check used -notmatch on lines read by Get-Content, which splits on newlines without understanding CSV quoting. If any sampled line lacked the delimiter (e.g. a continuation line from a multiline quoted field), the file was rejected. Changed to -match so the file is only rejected when no sampled lines contain the delimiter.

  • Multiline fields disabled by default in Strict mode (Import-DbaCsv Multiline quoted fields cause parse errors by default with RFC 4180 Strict mode #10189): AllowMultilineFields defaulted to $false despite QuoteMode defaulting to Strict ("RFC 4180 compliant"). RFC 4180 explicitly allows CR/LF inside quoted fields. Now AllowMultilineFields defaults to $true when QuoteMode is Strict, unless -SupportsMultiline is explicitly provided. Applied consistently across all three CsvReaderOptions construction sites (table creation, schema inference, and main import).

Fixes #10188
Fixes #10189

Test plan

  • Import a CSV where the first data row starts with a multiline quoted field (triggers Bug 1)
  • Import a CSV with multiline quoted fields deeper in the file without -SupportsMultiline (triggers Bug 2)
  • Import a standard CSV without multiline fields (no regression)
  • Import with -QuoteMode Lenient confirms multiline stays off unless -SupportsMultiline is passed
  • Existing Import-DbaCsv tests pass

(do Import-DbaCsv)

Two bugs caused valid CSV files with multiline quoted fields to be
rejected. The pre-validation used -notmatch which rejects the file if
ANY sampled line lacks the delimiter, but Get-Content splits mid-field
on embedded newlines. Changed to -match so only files with NO delimiter
matches are rejected. Also enabled AllowMultilineFields by default when
QuoteMode is Strict (RFC 4180), since the spec explicitly allows CR/LF
inside quoted fields.

Fixes dataplat#10188
Fixes dataplat#10189

(do Import-DbaCsv)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@potatoqualitee
Copy link
Member

Looks reasonable, thank you very much for the fix!

@potatoqualitee potatoqualitee merged commit 218a98a into dataplat:development Feb 26, 2026
3 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

2 participants