From 49677fe1605b9eaf881b2100f7ba46756c8c07b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Tellnes?= Date: Fri, 16 Feb 2018 11:41:57 +0100 Subject: [PATCH] Support quoted semicolons in csv field values And unskip corresponding unit test --- .../Core/Addml/DelimiterFileFormatReaderTest.cs | 2 +- src/Arkivverket.Arkade/Core/Addml/DelimiterFileFormatReader.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Arkivverket.Arkade.Test/Core/Addml/DelimiterFileFormatReaderTest.cs b/src/Arkivverket.Arkade.Test/Core/Addml/DelimiterFileFormatReaderTest.cs index b5be58bc9..99422a3d2 100644 --- a/src/Arkivverket.Arkade.Test/Core/Addml/DelimiterFileFormatReaderTest.cs +++ b/src/Arkivverket.Arkade.Test/Core/Addml/DelimiterFileFormatReaderTest.cs @@ -106,7 +106,7 @@ private void RecordShouldMatch(Record record, int fieldIndex, string name, strin record.Fields[fieldIndex].Value.Should().Be(value); } - [Fact(Skip = "Test is for a not yet implemented feature")] + [Fact] public void SemicolonsWithinQuotesAreNotInterpretedAsFieldDelimiters() { AddmlFlatFileDefinition addmlFlatFileDefinition = new AddmlFlatFileDefinitionBuilder() diff --git a/src/Arkivverket.Arkade/Core/Addml/DelimiterFileFormatReader.cs b/src/Arkivverket.Arkade/Core/Addml/DelimiterFileFormatReader.cs index 3a9775002..f607336ef 100644 --- a/src/Arkivverket.Arkade/Core/Addml/DelimiterFileFormatReader.cs +++ b/src/Arkivverket.Arkade/Core/Addml/DelimiterFileFormatReader.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; +using System.Text.RegularExpressions; using Arkivverket.Arkade.Core.Addml.Definitions; namespace Arkivverket.Arkade.Core.Addml @@ -52,7 +53,7 @@ private Record GetCurrentRecord() string currentLine = _lines.Current; - string[] strings = currentLine.Split(new[] {_fieldDelimiter}, StringSplitOptions.None); + string[] strings = Regex.Split(currentLine, $@"{_fieldDelimiter}(?=(?:[^""]*""[^""]*"")*[^""]*$)"); string recordIdentifier = null; if (_recordIdentifierPosition.HasValue)