Skip to content

Commit 7c12cb4

Browse files
authored
Merge pull request #138 from lesw/master
#123 Quotes are not escaped (CSV formatters)
2 parents 92987ff + 3b12036 commit 7c12cb4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/WebApiContrib.Core.Formatter.Csv/CsvOutputFormatter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ await streamWriter.WriteLineAsync(
9797

9898
var _val = val.Value.ToString();
9999

100-
//Check if the value contans a comma and place it in quotes if so
101-
if (_val.Contains(","))
100+
//Escape quotas
101+
_val = _val.Replace("\"", "\"\"");
102+
103+
//Check if the value contans a delimiter and place it in quotes if so
104+
if (_val.Contains(_options.CsvDelimiter))
102105
_val = string.Concat("\"", _val, "\"");
103106

104107
//Replace any \r or \n special characters from a new line with a space

0 commit comments

Comments
 (0)