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 escaping logic with nested double quotes and a comma at the end #73

Open
adridele opened this issue May 22, 2024 · 2 comments
Open

Comments

@adridele
Copy link

This csv row:

"Normal,\"quoted with nested \"double\" quotes, and comma at the end,\",normal 3,normal 4,normal 5"

will count 2 columns instead of 5.

Note, there is a nested double quotes, which with that alone it passes the test correctly (5 columns); but if you add a comma at the very end of the column (2nd column in this case) it will evaluate to only 2 columns instead of 5.

@adridele
Copy link
Author

adridele commented Jun 18, 2024

I just realized that it would be helpful to represent this input text as a C# raw literal:
"""Normal,"quoted with nested ""double"" quotes, and comma at the end,",normal 3,normal 4,normal 5"""
This literal will fail!
Again note, there is a nested double quotes, which with that alone it passes the test correctly (5 columns); but if you add a comma at the very end of the column (2nd column in this case) it will evaluate to only 2 columns instead of 5.

Here is a test case:

//Arrange...
var options = new CsvOptions // Defaults
{
    Separator = ',',
    HeaderMode = HeaderMode.HeaderAbsent, // Assumes first row is a header row
    AllowNewLineInEnclosedFieldValues = true, // Respects new line (either \r\n or \n) characters inside field values enclosed in double quotes.
};
string input = """Normal,"quoted with nested ""double"" quotes, and comma at the end,",normal 3,normal 4,normal 5""";

//Act...
var data = CsvReader.ReadFromText(input, options).First();

//Assert...
Assert.AreEqual(5, data.ColumnCount);

Copy link

Stale issue message

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

1 participant