Skip to content

Commit

Permalink
Fix step callback function when skipping empty lines (#714)
Browse files Browse the repository at this point in the history
Fixes #672
  • Loading branch information
seachicken authored and Sergi Almacellas Abellana committed Oct 17, 2019
1 parent ec26e72 commit 6f7e43e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,10 @@ License: MIT
_stepCounter += results.data.length;
if (_config.preview && _stepCounter > _config.preview)
_parser.abort();
else
else {
_results.data = _results.data[0];
userStep(_results, self);
}
}
};
}
Expand Down Expand Up @@ -1706,11 +1708,10 @@ License: MIT
}

/** Returns an object with the results, errors, and meta. */
function returnable(stopped, step)
function returnable(stopped)
{
var isStep = step || false;
return {
data: isStep ? data[0] : data,
data: data,
errors: errors,
meta: {
delimiter: delim,
Expand All @@ -1725,7 +1726,7 @@ License: MIT
/** Executes the user's step function and resets data & errors. */
function doStep()
{
step(returnable(undefined, true));
step(returnable());
data = [];
errors = [];
}
Expand Down
16 changes: 16 additions & 0 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,22 @@ var CUSTOM_TESTS = [
});
}
},
{
description: "Data is correctly parsed with steps when skipping empty lines",
expected: [['A', 'b', 'c'], ['d', 'E', 'f']],
run: function(callback) {
var data = [];
Papa.parse('A,b,c\n\nd,E,f', {
skipEmptyLines: true,
step: function(results) {
data.push(results.data);
},
complete: function() {
callback(data);
}
});
}
},
{
description: "Step is called with the contents of the row",
expected: ['A', 'b', 'c'],
Expand Down

0 comments on commit 6f7e43e

Please sign in to comment.