Skip to content

Commit

Permalink
Merge branch 'getfield_ignoreblank_missingfield' of github.com:Stefan…
Browse files Browse the repository at this point in the history
…Bertels/CsvHelper into StefanBertels-getfield_ignoreblank_missingfield
  • Loading branch information
JoshClose committed Oct 5, 2022
2 parents b077c5a + d739206 commit aa84807
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
7 changes: 0 additions & 7 deletions src/CsvHelper/CsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,8 @@ public virtual string? this[string name]

if (index >= parser.Count || index < 0)
{
if (ignoreBlankLines)
{
var args = new MissingFieldFoundArgs(null, index, context);
missingFieldFound?.Invoke(args);
}

return default;
}

Expand Down Expand Up @@ -484,11 +480,8 @@ public virtual string? this[string name]
if (index >= parser.Count || index < 0)
{
currentIndex = index;
if (ignoreBlankLines)
{
var args = new MissingFieldFoundArgs(null, index, context);
missingFieldFound?.Invoke(args);
}

return default;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/CsvHelper.Tests/CsvReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ public void GetMissingFieldGenericByIndexStrictTest()
null,
};

var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
IgnoreBlankLines = false,
};
var reader = new CsvReader(parserMock);
reader.Read();

Expand Down Expand Up @@ -881,7 +885,9 @@ public void DoNotIgnoreBlankLinesTest()
{
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
Delimiter = ",",
IgnoreBlankLines = false,
MissingFieldFound = null,
};
using (var stream = new MemoryStream())
using (var reader = new StreamReader(stream))
Expand Down
8 changes: 6 additions & 2 deletions tests/CsvHelper.Tests/Exceptions/ExceptionMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using CsvHelper.Configuration;
using CsvHelper.Tests.Mocks;
using CsvHelper.TypeConversion;
using Xunit;
Expand All @@ -17,13 +18,16 @@ public class ExceptionMessageTests
[Fact]
public void GetMissingFieldTest()
{
var parser = new ParserMock
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
IgnoreBlankLines = false,
};
var parser = new ParserMock(config)
{
{ "Id", "Name" },
{ "a", "b" },
null
};

var reader = new CsvReader(parser);
reader.Read();
reader.Read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void SingleColumnCsvWithHeadersAndSingleNullDataRowTest()
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
IgnoreBlankLines = false,
MissingFieldFound = null,
};
var parser = new ParserMock(config)
{
Expand Down Expand Up @@ -55,6 +56,7 @@ public void SingleColumnCsvWithHeadersAndPresentAndNullDataRowTest()
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
IgnoreBlankLines = false,
MissingFieldFound = null,
};
var parser = new ParserMock(config)
{
Expand Down Expand Up @@ -118,6 +120,7 @@ public void TwoColumnCsvWithHeadersAndPresentAndNullDataRowTest()
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
IgnoreBlankLines = false,
MissingFieldFound = null,
};
var parser = new ParserMock(config)
{
Expand Down

0 comments on commit aa84807

Please sign in to comment.