Browse Source

Treat JSON null as empty value

pull/82/head
Vinicius Horewicz 11 years ago
parent
commit
6d21cbc11a
  1. 2
      papaparse.js
  2. 5
      tests/test-cases.js

2
papaparse.js

@ -364,7 +364,7 @@ @@ -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, '""');

5
tests/test-cases.js

@ -640,5 +640,10 @@ var UNPARSE_TESTS = [ @@ -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'
}
];
Loading…
Cancel
Save