ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.11k stars 440 forks source link

linefeeds in quoted values #69

Closed petehug closed 6 years ago

petehug commented 6 years ago

Consider this csv file: col1,col2,col3,col4 1,1,"a",0 1,2,"a b",0

The second row after the header has a quoted value with a cr/lf. This throws a error::escaped_string_not_closed() exception.

ben-strasser commented 6 years ago

Hi,

thanks for the report.

Can you please provide a minimum C++ file that demonstrates the problem?

Best Regards Dr. Ben Strasser

On 07/19/2018 07:39 AM, Pete Hug wrote:

Consider this csv file: |col1,col2,col3,col4 1,1,"a",0 1,2,"a b",0| The first row after the header has a quoted value with a cr/lf. This throws a error::escaped_string_not_closed() exception.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ben-strasser/fast-cpp-csv-parser/issues/69, or mute the thread https://github.com/notifications/unsubscribe-auth/ALaAj3dEi2UzHvMi5OB81Xh6erJsAYDDks5uIBt0gaJpZM4VVx4T.

petehug commented 6 years ago

Hi Ben,

CSVStrasser.zip

The attached file contains test.csv. The second row of data contains a string in the 3rd column with an embedded cr/lf (yes it is windows, but I'm sure the same issue arises under unix if you replace it with a newline).

The first data row is processed OK and the second throws an escaped_string_not_closed exception.

Thanks, Pete

petehug commented 6 years ago

BTW, here is how the Notepad++ plugin CSV Query shows the parsed output from the test file (the last column shows you the value of col3 in hex and demonstrates that the cr/lf is correctly preserved between the a and b of 'ab').

test

petehug commented 6 years ago

Hi Ben,

I made some changes to csv.h to address this issue (see below).

I haven't tried, but I'm almost certain that reporting of parse errors may report invalid line number reference if the error occurs after a row with line breaks in one or more values.

Thanks, Pete

csv.h.txt

ben-strasser commented 6 years ago

Sorry for the late response. From your first post it was unclear to me what you wanted to achieve. Now I understand but sorry: wont implement.

Newlines within quotes have been requested many times in the past and it's a feature that will now be implemented. For a detailed reasoning, please look at the exiting issues. The summary is:

Best Regards Ben Strasser