@ -364,7 +364,7 @@
// Encloses a value around quotes if needed (makes a value safe for CSV insertion)
function safe(str, col)
{
if (typeof str === "undefined")
if (typeof str === "undefined" || str === null)
return "";
str = str.toString().replace(/"/g, '""');
@ -640,5 +640,10 @@ var UNPARSE_TESTS = [
description: "Mismatched field counts in rows",
input: [['a', 'b', 'c'], ['d', 'e'], ['f']],
expected: 'a,b,c\r\nd,e\r\nf'
},
description: "JSON null is treated as empty value",
input: [{ "Col1": "a", "Col2": null, "Col3": "c" }],
expected: 'Col1,Col2,Col3\r\na,,c'
}
];