Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit d689420

Browse files
committed
don't double deserialize quoted csv fields
1 parent 4fec2a0 commit d689420

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/ServiceStack.Text/CsvReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static List<string> ParseFields(string line, Func<string,string> parseFn)
7171
while (++i <= len)
7272
{
7373
var value = EatValue(line, ref i);
74-
to.Add(parseFn != null ? parseFn(value.FromCsvField()) : value.FromCsvField());
74+
to.Add(parseFn != null ? parseFn(value) : value);
7575
}
7676

7777
return to;

tests/ServiceStack.Text.Tests/CsvSerializerTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,20 @@ public void Can_serialize_single_StringDictionary_or_StringKvps()
377377
Assert.That(kvps.ToCsv().NormalizeNewLines(), Is.EqualTo("Id,CustomerId\n1,ALFKI").Or.EqualTo("CustomerId,Id\nALFKI,1"));
378378
}
379379

380+
[Test]
381+
public void Can_serialize_fields_with_double_quotes()
382+
{
383+
var person = new Person { Id = 1, Name = "\"Mr. Lee\"" };
384+
Assert.That(person.ToCsv().NormalizeNewLines(), Is.EqualTo("Id,Name\n1,\"\"\"Mr. Lee\"\"\""));
385+
var fromCsv = person.ToCsv().FromCsv<Person>();
386+
Assert.That(fromCsv, Is.EqualTo(person));
387+
388+
person = new Person { Id = 1, Name = "\"Anon\" Review" };
389+
Assert.That(person.ToCsv().NormalizeNewLines(), Is.EqualTo("Id,Name\n1,\"\"\"Anon\"\" Review\""));
390+
fromCsv = person.ToCsv().FromCsv<Person>();
391+
Assert.That(fromCsv, Is.EqualTo(person));
392+
}
393+
380394
[Test]
381395
public void serialize_Category()
382396
{

0 commit comments

Comments
 (0)