Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong separator detection inside quotes #614

Open
letarak opened this issue Oct 18, 2022 · 1 comment
Open

Wrong separator detection inside quotes #614

letarak opened this issue Oct 18, 2022 · 1 comment

Comments

@letarak
Copy link

letarak commented Oct 18, 2022

version 3.6.0

If we have value inside quotes and escaped quotes placed before separator, then parse result would be wrong

test case:

var csv = @"John,Doe,120 any st.,""\""Anytown\"", WW"",08123";

var readerConfiguration = new ExcelReaderConfiguration
{
    FallbackEncoding = Encoding.UTF8,
    AutodetectSeparators = new [] { ',' }
};

await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(csv));
using var reader = ExcelReaderFactory.CreateCsvReader(stream, readerConfiguration);

reader.Read();

var values = Enumerable.Range(0, reader.FieldCount).Select(it => reader[it]);

Console.WriteLine(string.Join("\n", values));

actual output:

John
Doe
120 any st.
\Anytown\"
WW"
08123

expected output:

John
Doe
120 any st.
"Anytown", WW
08123
@appel1
Copy link
Collaborator

appel1 commented Jun 19, 2023

We probably need to add a setting for configuring what escape character to use instead of double quotes ('"')? Can't think of a good way to autodetect it.

Creating a csv file using Excel with the values from your expected output instead gave me this:

John,Doe,120 any st.,"""Anytown"", WW",8123

Which gave me the following output using your test case (changed to read from file instead of inline):

John
Doe
120 any st.
"Anytown", WW
8123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants