-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
Describe the bug
With DetectDelimiter = true and AllowComments = true, the delimiter detection includes commented lines in the lines where it's looking for delimiters. If a comment line does not include any delimiter then delimiter detection will fail.
See here for where the detection will fail if the commented line has no delimiters https://github.com/JoshClose/CsvHelper/blob/master/src/CsvHelper/Configuration/ConfigurationFunctions.cs#L234-L248.
To Reproduce
using CsvHelper;
using CsvHelper.Configuration;
using System.Globalization;
using System.Text;
class Program
{
static void Main(string[] args)
{
var s = new StringBuilder();
s.Append("#Some comment\r\n");
s.Append("A;B;C\r\n");
s.Append("1;2;3\r\n");
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
Comment = '#',
AllowComments = true,
DetectDelimiter = true,
IgnoreBlankLines = true
};
using (var reader = new StringReader(s.ToString()))
using (var csv = new CsvReader(reader, config))
{
var x = csv.GetRecords<Foo>().ToList();
}
}
public class Foo
{
public string A { get; set; }
public string B { get; set; }
public string C { get; set; }
}
}Expected behavior
The delimiter detection should ignore any comment lines when AllowComments = true