Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ License: MIT
var nullLine = hasHeader ? Object.keys(data[row]).length === 0 : data[row].length === 0;
if (skipEmptyLines && !hasHeader)
{
emptyLine = skipEmptyLines === 'greedy' ? data[row].join('').trim() === '' : data[row].length === 1 && data[row][0].length === 0;
emptyLine = skipEmptyLines === 'greedy' ? data[row].join('').trim() === '' : data[row].length === 1 && (data[row][0] === null || data[row][0] === undefined || data[row][0].length === 0);
}
if (skipEmptyLines === 'greedy' && hasHeader) {
var line = [];
Expand Down
25 changes: 25 additions & 0 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,31 @@ var UNPARSE_TESTS = [
config: {skipEmptyLines: 'greedy'},
expected: '1,2\r\n3,4'
},
{
description: "Skips single-cell rows containing null or undefined when skipEmptyLines is true",
notes: "Regression test for issue #1163: unparse threw a TypeError when a row contained a single null or undefined value",
input: [[null], ['hello'], [undefined], ['world']],
config: {skipEmptyLines: true},
expected: 'hello\r\nworld'
},
{
description: "Returns empty rows for single-cell rows containing null or undefined when skipEmptyLines is false",
input: [[null], ['hello'], [undefined], ['world']],
config: {skipEmptyLines: false},
expected: '\r\nhello\r\n\r\nworld'
},
{
description: "Skips single-cell rows containing null or undefined when skipEmptyLines is 'greedy'",
input: [[null], ['hello'], [undefined], ['world']],
config: {skipEmptyLines: 'greedy'},
expected: 'hello\r\nworld'
},
{
description: "Does not skip single-cell rows containing 0 when skipEmptyLines is true",
input: [[0], ['hello']],
config: {skipEmptyLines: true},
expected: '0\r\nhello'
},
{
description: "Returns empty rows when empty rows are passed and skipEmptyLines is false with headers",
input: [{a: null, b: ' '}, {}, {a: '1', b: '2'}],
Expand Down
Loading