Skip to content

Commit

Permalink
Fix CSV parsing issue when first cell is empty (#707)
Browse files Browse the repository at this point in the history
Closes #706
  • Loading branch information
GraceDmello authored and Sergi Almacellas Abellana committed Sep 12, 2019
1 parent bacf4f2 commit 94d7bf9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ License: MIT
}

var incrementBy = 1;
if (!_results.data[0] || Array.isArray(_results.data[0]))
if (!_results.data.length || Array.isArray(_results.data[0]))
{
_results.data = _results.data.map(processRow);
incrementBy = _results.data.length;
Expand Down
15 changes: 15 additions & 0 deletions tests/node-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ describe('PapaParse', function() {
});
});


it('piped streaming CSV should be correctly parsed when header is true', function(done) {
var data = [];
var readStream = fs.createReadStream(__dirname + '/sample-header.csv', 'utf8');
var csvStream = readStream.pipe(Papa.parse(Papa.NODE_STREAM_INPUT, {header: true}));
csvStream.on('data', function(item) {
data.push(item);
});
csvStream.on('end', function() {
assert.deepEqual(data[0], { title: 'test title 01', name: 'test name 01' });
assert.deepEqual(data[1], { title: '', name: 'test name 02' });
done();
});
});

it('should support pausing and resuming on same tick when streaming', function(done) {
var rows = [];
Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), {
Expand Down
3 changes: 3 additions & 0 deletions tests/sample-header.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title,name
test title 01,test name 01
,test name 02

0 comments on commit 94d7bf9

Please sign in to comment.