Browse Source

Fix CSV parsing issue when first cell is empty (#707)

Closes #706
pull/714/head
Grace D'Mello 5 years ago committed by Sergi Almacellas Abellana
parent
commit
94d7bf939a
  1. 2
      papaparse.js
  2. 15
      tests/node-tests.js
  3. 3
      tests/sample-header.csv

2
papaparse.js

@ -1259,7 +1259,7 @@ License: MIT
} }
var incrementBy = 1; 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); _results.data = _results.data.map(processRow);
incrementBy = _results.data.length; incrementBy = _results.data.length;

15
tests/node-tests.js

@ -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) { it('should support pausing and resuming on same tick when streaming', function(done) {
var rows = []; var rows = [];
Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), { Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), {

3
tests/sample-header.csv

@ -0,0 +1,3 @@
title,name
test title 01,test name 01
,test name 02
1 title name
2 test title 01 test name 01
3 test name 02
Loading…
Cancel
Save