You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
In case a csv string starts with BOM I get exception
CsvHelper.BadDataException: You can ignore bad data by setting BadDataFound to null.
CsvHelper.BadDataException
You can ignore bad data by setting BadDataFound to null.
IReader state:
ColumnCount: 2
CurrentIndex: -1
HeaderRecord:
IParser state:
ByteCount: 0
CharCount: 19
Row: 1
RawRow: 1
Count: 2
RawRecord:
"username";"email"
To Reproduce
using System.Globalization;
using System.Text;
using CsvHelper;
using Xunit;
namespace CsvHelperBugTests;
public class ErrorThrow
{
[Fact]
public void Bug()
{
string stringContent = """
"username";"email"
""";
var preamble = Encoding.UTF8.GetPreamble();
var bom = Encoding.UTF8.GetString(preamble);
var stringContentWithBOM = bom + stringContent;
using (var reader = new StringReader(stringContentWithBOM))
{
using (var csv = new CsvReader(reader,
new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture)
{
Delimiter = ";",
}))
{
var records = csv.GetRecords<dynamic>();
var a = records.ToList(); // exception
}
}
}
}
Expected behavior
just ignore first symbol of BOM
Additional context
to fix a problem I have to do:
var preamble = Encoding.UTF8.GetPreamble();
var bom = Encoding.UTF8.GetString(preamble);
string stringContent2;
if (stringContent[0] == bom[0])
{
stringContent2 = stringContent.Remove(0, 1);
}
The text was updated successfully, but these errors were encountered:
Describe the bug
In case a csv string starts with BOM I get exception
To Reproduce
Expected behavior
just ignore first symbol of BOM
Additional context
to fix a problem I have to do:
The text was updated successfully, but these errors were encountered: