Skip to content

Commit 38c78f3

Browse files
kriszypkfranqueiro
authored andcommitted
Properly handle non-string values in CSV serialization
(cherry picked from commit f2f620a)
1 parent a83b7ac commit 38c78f3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Csv.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ define([
157157
if (i > -1) { output += newline; }
158158
for (j = 0; j < fieldNames.length; j++) {
159159
value = i < 0 ? fieldNames[j] : data[i][fieldNames[j]];
160+
if (value === null || value === undefined) {
161+
value = '';
162+
}
163+
if (typeof value !== 'string') {
164+
value = value.toString();
165+
}
160166
needsQuotes = alwaysQuote ||
161167
value.indexOf('"') >= 0 || value.indexOf(delimiter) >= 0;
162168
output += (j > 0 ? delimiter : '') +

0 commit comments

Comments
 (0)