Skip to content

Commit 3b12036

Browse files
author
lechoslaw
committed
#123 Quotes are not escaped (CSV formatters)
1 parent 2e46972 commit 3b12036

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,9 +97,12 @@ 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
100+
//Escape quotas
101+
_val = _val.Replace("\"", "\"\"");
102+
103+
//Check if the value contans a delimiter and place it in quotes if so
101104
if (_val.Contains(_options.CsvDelimiter))
102-
_val = string.Concat("\"", _val.Replace("\"", "\"\""), "\"");
105+
_val = string.Concat("\"", _val, "\"");
103106

104107
//Replace any \r or \n special characters from a new line with a space
105108
if (_val.Contains("\r"))

0 commit comments

Comments
 (0)