diff --git a/RecordParser.Test/QuotedFileReaderTest.cs b/RecordParser.Test/QuotedFileReaderTest.cs index 1f4b4b8..90c1e64 100644 --- a/RecordParser.Test/QuotedFileReaderTest.cs +++ b/RecordParser.Test/QuotedFileReaderTest.cs @@ -3,6 +3,7 @@ using RecordParser.Extensions; using System; using System.IO; +using System.Linq; using System.Text; using Xunit; @@ -18,6 +19,59 @@ public class Quoted public Gender Gender; } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void foo(bool parallel) + { + // Arrange + + var fileContent = """ + A,B,C,D + "x + y",2,3,4 + """; + + var reader = new StringReader(fileContent); + var options = new VariableLengthReaderRawOptions + { + HasHeader = true, + ContainsQuotedFields = true, + ColumnCount = 4, + Separator = ",", + ParallelismOptions = new() + { + Enabled = parallel, + MaxDegreeOfParallelism = 2 + }, + }; + + // Act + + var records = reader.ReadRecordsRaw(options, getField => + { + var record = new + { + A = getField(0), + B = getField(1), + C = getField(2), + D = getField(3) + }; + return record; + }).ToList(); + + // Assert + + records.Should().HaveCount(1); + + var record = records.Single(); + record.A.Should().Be("x\r\ny"); + record.B.Should().Be("2"); + record.C.Should().Be("3"); + record.D.Should().Be("4"); + } + [Theory] [InlineData(true)] [InlineData(false)] diff --git a/RecordParser/Extensions/FileReader/RowReaders/RowByQuote.cs b/RecordParser/Extensions/FileReader/RowReaders/RowByQuote.cs index 1c436c0..0c0f83e 100644 --- a/RecordParser/Extensions/FileReader/RowReaders/RowByQuote.cs +++ b/RecordParser/Extensions/FileReader/RowReaders/RowByQuote.cs @@ -58,7 +58,7 @@ public override IEnumerable> ReadLines() else if (c == quote) { ReadOnlySpan span = buffer.AsSpan().Slice(0, i - 1); - var isQuotedField = span.TrimEnd().EndsWith(separator); + var isQuotedField = i == 1 || span[span.Length - 1] == '\n' || span.TrimEnd().EndsWith(separator); if (isQuotedField is false) continue;