vincentlaucsb / csv-parser

A high-performance, fully-featured CSV parser and serializer for modern C++.
MIT License
901 stars 150 forks source link

Minimal quoting does not quote if line breaks are contained in fields #171

Closed likeazir closed 3 years ago

likeazir commented 3 years ago

I am using the single header version of this csv parser as found in this repo.

When writing a csv, line breaks should be enclosed in quotes, according to rfc 4180 2.6 The function _csv_escape, however, does not quote those fields. This leads to the situation that thsi csv reader can't read it's own csvs anymore, which is a bit unfortunate.

It works for me to just also test for \r and \n and then escape a string. While looking at the code, however, I noticed this in _csv_escape

if (!quote_escape) {
    if (quote_minimal) return std::string(in);
    else {
        std::string ret(Quote, 1);
        ret += in.data();
        ret += Quote;
    }
}

which looks odd to me, as ret goes out of scope

vincentlaucsb commented 3 years ago

This is legitimate bug, and a bit embarrassing. Thanks for reporting this.

vincentlaucsb commented 3 years ago

Should be fixed by #177