Search code examples
c#csvparsingcsvhelper

CsvParser misses some places with specified delimeter


I have a C# code that suppose to parse data and uses "@BELL" as Delimeter. (BELL is ASCII code)

But some values have another "@" at the end of it, and thus it looks like this "0.0000000@SS-AA&-BB-C)@@021328@STRING_Price". The CsvParser does split on the first "@" but misses the 2nd occurrence (where it has "@@") and splits fine on the 3rd occurrence. The data cannot be modified in the source and has to be as it is.

We're using CsvHelper v 15.0.0.

Is it a known CsvParser issue? (I was trying to get away without adding additional parsing/replacement).

Here is my code (I have simplified it and use local file for the test purpose, but in reality it goes to the AzureBlobStorage):

private static readonly string delimiter = "@" + new string('\u0007', 1);
private static string filePath = "C:\\Downloads\\000_From_Blob";

private static IEnumerable<string[]> ParseCompressedClientFormattedStream(string filePath, string delimiter)
{
    using (var remoteStream = File.OpenText(filePath))
    {
        using (var csvReader = new CsvParser(remoteStream, new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = delimiter.ToString(), BadDataFound = null }))
        {
                for (; ; )
                {
                    var line = csvReader.Read();
                    if (line != null) yield return line;
                    else break;
                }
         }
    }
}

Here are 2 sample lines from the source file. The first line being parsed correctly. But the 2nd one does not split where it has double "@":

110@A778@10211@2@Joe@0.0000000@SS-AA&-BB-C)@@SS-AA&-BB-C)@021328@STRING_Price@$9.99@@False
111@A778@10211@2@Joe@0.0000000@SS-AA&-BB-C)@@@SS-AA&-BB-C)@@021328@STRING_Price@$9.99@@False

enter image description here


Solution

  • It appears to be a bug in CsvHelper package of v15.0.0. Updating it to the latest version 15.0.5 - has fixed the issue.