Add newlines to list of special CSV chars for quoting.

This commit is contained in:
Andrew Lalis 2026-03-27 07:59:07 -04:00
parent 44b19ed36c
commit 045e3a5c95
1 changed files with 3 additions and 1 deletions

View File

@ -30,7 +30,9 @@ struct CsvStreamWriter(S) if (isByteOutputStream!S) {
import std.regex : replaceAll, regex;
import std.string : indexOf;
string s = value.to!string();
bool shouldValueBeQuoted = indexOf(s, '"') != -1 || indexOf(s, ',') != -1;
bool shouldValueBeQuoted = indexOf(s, '"') != -1 ||
indexOf(s, ',') != -1 ||
indexOf(s, '\n') != -1;
s = replaceAll(value.to!string(), regex("\""), "\"\"");
if (shouldValueBeQuoted) {
s = "\"" ~ s ~ "\"";