Browse Source

Merge pull request #82 from wicz/handle-json-null

Treat JSON null as empty value in unparse
pull/93/head
Matt Holt 11 years ago
parent
commit
a0991ad6b0
  1. 2
      papaparse.js
  2. 5
      tests/test-cases.js

2
papaparse.js

@ -364,7 +364,7 @@
// Encloses a value around quotes if needed (makes a value safe for CSV insertion) // Encloses a value around quotes if needed (makes a value safe for CSV insertion)
function safe(str, col) function safe(str, col)
{ {
if (typeof str === "undefined") if (typeof str === "undefined" || str === null)
return ""; return "";
str = str.toString().replace(/"/g, '""'); str = str.toString().replace(/"/g, '""');

5
tests/test-cases.js

@ -640,5 +640,10 @@ var UNPARSE_TESTS = [
description: "Mismatched field counts in rows", description: "Mismatched field counts in rows",
input: [['a', 'b', 'c'], ['d', 'e'], ['f']], input: [['a', 'b', 'c'], ['d', 'e'], ['f']],
expected: 'a,b,c\r\nd,e\r\nf' 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'
} }
]; ];
Loading…
Cancel
Save