From 6f7e43edd375133d813336cceef1dbda38584ebf Mon Sep 17 00:00:00 2001 From: Seito Tanaka Date: Fri, 18 Oct 2019 05:49:19 +0900 Subject: [PATCH] Fix step callback function when skipping empty lines (#714) Fixes #672 --- papaparse.js | 11 ++++++----- tests/test-cases.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/papaparse.js b/papaparse.js index b624e50..f1674f5 100755 --- a/papaparse.js +++ b/papaparse.js @@ -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 } /** 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 /** Executes the user's step function and resets data & errors. */ function doStep() { - step(returnable(undefined, true)); + step(returnable()); data = []; errors = []; } diff --git a/tests/test-cases.js b/tests/test-cases.js index 0c4ab04..58a85f0 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -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'],