diff --git a/papaparse.js b/papaparse.js index 9f8a560..ae4b70d 100755 --- a/papaparse.js +++ b/papaparse.js @@ -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; diff --git a/tests/node-tests.js b/tests/node-tests.js index a067bfe..9c57a22 100644 --- a/tests/node-tests.js +++ b/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) { var rows = []; Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), { diff --git a/tests/sample-header.csv b/tests/sample-header.csv new file mode 100644 index 0000000..bc2472b --- /dev/null +++ b/tests/sample-header.csv @@ -0,0 +1,3 @@ +title,name +test title 01,test name 01 +,test name 02