Wrong escaping logic with nested double quotes and a comma at the end
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.
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);
Stale issue message