@@ -635,6 +635,12 @@ function Import-DbaCsv {
635635 $options.MaxDecompressedSize = $MaxDecompressedSize
636636 $options.SkipRows = $SkipRows
637637 $options.DuplicateHeaderBehavior = [Dataplat.Dbatools.Csv.Reader.DuplicateHeaderBehavior ]::$DuplicateHeaderBehavior
638+ # RFC 4180 allows CR/LF inside quoted fields, so enable multiline by default in Strict mode
639+ if ($QuoteMode -eq " Strict" -and -not $PSBoundParameters.ContainsKey (" SupportsMultiline" )) {
640+ $options.AllowMultilineFields = $true
641+ } else {
642+ $options.AllowMultilineFields = $SupportsMultiline.IsPresent
643+ }
638644
639645 try {
640646 $reader = [Dataplat.Dbatools.Csv.Reader.CsvDataReader ]::new($Path , $options )
@@ -966,7 +972,7 @@ WHERE c.object_id = OBJECT_ID(@tableName)
966972 Stop-Function - Continue - Message " Failure reading $file " - ErrorRecord $_
967973 }
968974 if (-not $SingleColumn ) {
969- if ($firstlines -notmatch [regex ]::Escape($Delimiter )) {
975+ if (-not ( $firstlines -match [regex ]::Escape($Delimiter ) )) {
970976 Stop-Function - Message " Delimiter ($Delimiter ) not found in first few rows of $file . If this is a single column import, please specify -SingleColumn"
971977 return
972978 }
@@ -1104,6 +1110,12 @@ WHERE c.object_id = OBJECT_ID(@tableName)
11041110 $inferOptions.Escape = $Escape
11051111 $inferOptions.Comment = $Comment
11061112 $inferOptions.Encoding = [System.Text.Encoding ]::$Encoding
1113+ # RFC 4180 allows CR/LF inside quoted fields, so enable multiline by default in Strict mode
1114+ if ($QuoteMode -eq " Strict" -and -not $PSBoundParameters.ContainsKey (" SupportsMultiline" )) {
1115+ $inferOptions.AllowMultilineFields = $true
1116+ } else {
1117+ $inferOptions.AllowMultilineFields = $SupportsMultiline.IsPresent
1118+ }
11071119 if ($PSBoundParameters.DateTimeFormats ) {
11081120 $inferOptions.DateTimeFormats = $DateTimeFormats
11091121 }
@@ -1299,7 +1311,12 @@ WHERE c.object_id = OBJECT_ID(@tableName)
12991311 $csvOptions.CollectParseErrors = $CollectParseErrors.IsPresent
13001312 $csvOptions.MaxParseErrors = $MaxParseErrors
13011313 $csvOptions.SkipEmptyLines = $SkipEmptyLine.IsPresent
1302- $csvOptions.AllowMultilineFields = $SupportsMultiline.IsPresent
1314+ # RFC 4180 allows CR/LF inside quoted fields, so enable multiline by default in Strict mode
1315+ if ($QuoteMode -eq " Strict" -and -not $PSBoundParameters.ContainsKey (" SupportsMultiline" )) {
1316+ $csvOptions.AllowMultilineFields = $true
1317+ } else {
1318+ $csvOptions.AllowMultilineFields = $SupportsMultiline.IsPresent
1319+ }
13031320 $csvOptions.UseColumnDefaults = $UseColumnDefault.IsPresent
13041321 if ($PSBoundParameters.MaxQuotedFieldLength ) {
13051322 $csvOptions.MaxQuotedFieldLength = $MaxQuotedFieldLength
0 commit comments