Skip to content

Commit

Permalink
encoding/csv: clarify that Writer uses different line break than RFC …
Browse files Browse the repository at this point in the history
…4180 by default

Package documentation of encoding/csv says:

> this package supports the format described in RFC 4180.

https://pkg.go.dev/encoding/csv#section-documentation

According to section 2 of RFC 4180:

> Each record is located on a separate line, delimited by a line break (CRLF).

https://www.rfc-editor.org/rfc/rfc4180.html#section-2

On the other hand, encoding/csv.Writer uses LF (not CRLF) as newline character by default.

> If [Writer.UseCRLF] is true, the Writer ends each output line with \r\n instead of \n.

https://pkg.go.dev/encoding/csv#Writer

https://github.com/golang/go/blob/1259a30a588392e6a1efbed9e0c7d893c72187fa/src/encoding/csv/writer.go#L115-L119

Strictly speaking, this behavior is different from RFC 4180.
Package documentation would improve if we clarify that point.
  • Loading branch information
nobishino committed May 11, 2024
1 parent 4721f95 commit e322fed
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/encoding/csv/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

// Package csv reads and writes comma-separated values (CSV) files.
// There are many kinds of CSV files; this package supports the format
// described in RFC 4180.
// described in RFC 4180, except that [Writer] uses LF
// instead of CRLF as newline character by default.
//
// A csv file contains zero or more records of one or more fields per record.
// Each record is separated by the newline character. The final record may
Expand Down

0 comments on commit e322fed

Please sign in to comment.