Skip to content

Commit

Permalink
fixcolumns config works with input type object (#919)
Browse files Browse the repository at this point in the history
Closes #918
  • Loading branch information
TheSlimvReal committed Mar 15, 2022
1 parent 8dba33e commit 4132d81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ License: MIT
if (Array.isArray(_input.data))
{
if (!_input.fields)
_input.fields = _input.meta && _input.meta.fields;
_input.fields = _input.meta && _input.meta.fields || _columns;

if (!_input.fields)
_input.fields = Array.isArray(_input.data[0])
Expand Down
7 changes: 7 additions & 0 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,13 @@ var UNPARSE_TESTS = [
config: {columns: ['a', 'b', 'c']},
expected: 'a,b,c\r\n1,2,\r\n\r\n3,,4'
},
{
description: "Column option used to manually specify keys with input type object",
notes: "Should not throw any error when attempting to serialize key not present in object. Columns are different than keys of the first object. When an object is missing a key then the serialized value should be an empty string.",
input: { data: [{a: 1, b: '2'}, {}, {a: 3, d: 'd', c: 4,}] },
config: {columns: ['a', 'b', 'c']},
expected: 'a,b,c\r\n1,2,\r\n\r\n3,,4'
},
{
description: "Use different escapeChar",
input: [{a: 'foo', b: '"quoted"'}],
Expand Down

0 comments on commit 4132d81

Please sign in to comment.