Skip to content

Commit

Permalink
Merge branch 'DKStudio-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshClose committed Jan 25, 2024
2 parents 4deab1a + c4a49d4 commit 2b3ca3b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CsvHelper/CsvDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CsvDataReader(CsvReader csv, DataTable schemaTable = null)

csv.Read();

if (csv.Configuration.HasHeaderRecord)
if (csv.Configuration.HasHeaderRecord && csv.HeaderRecord == null)
{
csv.ReadHeader();
}
Expand Down
42 changes: 42 additions & 0 deletions tests/CsvHelper.Tests/Issues/Issue2060.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Data;
using System.Globalization;
using System.IO;
using Xunit;

namespace CsvHelper.Tests.Issues
{
public class Issue2060
{
[Fact]
public void Test1()
{
var data =
"""
A
B
C
Id,Name
1,Jeff
2,Kevin
""";
using var reader = new StringReader(data);
using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
while (csv.Read())
{
if (csv[0] == "Id")
{
break;
}
}

csv.ReadHeader();

using var dr = new CsvDataReader(csv);
var dt = new DataTable();
dt.Load(dr);

Assert.Equal("Id", dt.Columns[0].ColumnName);
Assert.Equal("Name", dt.Columns[1].ColumnName);
}
}
}

0 comments on commit 2b3ca3b

Please sign in to comment.