Skip to content

Commit

Permalink
Merge pull request #1484 from bonjune/rfc-4180
Browse files Browse the repository at this point in the history
  • Loading branch information
cartermp authored Apr 30, 2023
2 parents 13afb37 + d0a9884 commit a5d36ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/FSharp.Data.Csv.Core/CsvRuntime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ type CsvFile<'RowType>

use writer = writer

// RFC 4180 (https://www.rfc-editor.org/rfc/rfc4180)
// 2. Definition of the CSV Format
// Each record is located on a separated line, delimited by a line break CRLF
writer.NewLine <- "\r\n"

let nullSafeguard str =
match str with
| null -> String.Empty
Expand Down
5 changes: 3 additions & 2 deletions tests/FSharp.Data.Tests/CsvProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ let ``Can create type for small document``() =

[<Test>]
let ``CsvFile.Rows is re-entrant if the underlying stream is``() =
let csv = CsvFile.Load(Path.Combine(__SOURCE_DIRECTORY__, "Data/SmallTest.csv"))
let csv = CsvFile.Load(Path.Combine(__SOURCE_DIRECTORY__, "Data/SmallTest.csv"))
let twice = [ yield! csv.Rows; yield! csv.Rows ]
twice |> Seq.length |> should equal 6

Expand Down Expand Up @@ -465,7 +465,8 @@ let ``Parse single row with trailing newline``() =
let ``Parse two rows``() =
let rows = SimpleWithStrCsv.ParseRows("false,abc, 31\ntrue, def, 42")
rows.Length |> should equal 2
(new SimpleWithStrCsv(rows)).SaveToString() |> should equal ("Column1,ColumnB,Column3" + Environment.NewLine + "false,abc,31" + Environment.NewLine + "true, def,42" + Environment.NewLine)
(new SimpleWithStrCsv(rows)).SaveToString() |> should equal ("Column1,ColumnB,Column3" + "\r\n" + "false,abc,31" + "\r\n" + "true, def,42" + "\r\n")
// (new SimpleWithStrCsv(rows)).SaveToString() |> should equal ("Column1,ColumnB,Column3" + Environment.NewLine + "false,abc,31" + Environment.NewLine + "true, def,42" + Environment.NewLine)

let [<Literal>] csvWithDataEndingWithSeparator = """
Name|Company |Email|Password
Expand Down

0 comments on commit a5d36ed

Please sign in to comment.