Browse Source

Fix step callback function when skipping empty lines (#714)

Fixes #672
pull/723/head
Seito Tanaka 5 years ago committed by Sergi Almacellas Abellana
parent
commit
6f7e43edd3
  1. 11
      papaparse.js
  2. 16
      tests/test-cases.js

11
papaparse.js

@ -1036,8 +1036,10 @@ License: MIT @@ -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);
}
}
};
}
@ -1706,11 +1708,10 @@ License: MIT @@ -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,
@ -1725,7 +1726,7 @@ License: MIT @@ -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 = [];
}

16
tests/test-cases.js

@ -1973,6 +1973,22 @@ var CUSTOM_TESTS = [ @@ -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'],

Loading…
Cancel
Save