CSV standard regarding end of a row

1.3k views Asked by At

I am writing a CSV parser and I want it to comply with this standards. It states:

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

How should I handle rows ending with only CR of LF character? Should I treat them as literals and pass to field, interpret as a row end. Or maybe dub the file malformed?

I guess, that most flexible solution would be to accept either type of line end, but I am trying to figure out what standards say.

What do you think about it?

1

There are 1 answers

3
Danny_ds On BEST ANSWER

You should certainly not treat them as malformed, because there can be different line endings on Linux, Windows and Mac for example.

It's better to support them all.

Also, fields can have newlines in them as well, if they are properly quoted. So you'll need to check for that too.

For example:

123,"test on 2 
lines",456

is a valid csv row.