Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept any header name (inc. __proto__) #992

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions papaparse.js
Expand Up @@ -1247,7 +1247,7 @@ License: MIT

function processRow(rowSource, i)
{
var row = _config.header ? {} : [];
var row = _config.header ? Object.create(null) : [];

var j;
for (j = 0; j < rowSource.length; j++)
Expand Down Expand Up @@ -1473,7 +1473,7 @@ License: MIT
var headers = firstLine.split(delim);
var separator = '_';
var headerMap = new Set();
var headerCount = {};
var headerCount = Object.create(null);
var duplicateHeaders = false;

for (var j in headers) {
Expand Down
11 changes: 11 additions & 0 deletions tests/node-tests.js
Expand Up @@ -5,6 +5,7 @@ var Papa = require("../papaparse.js");
var fs = require('fs');
var assert = require('assert');
var longSampleRawCsv = fs.readFileSync(__dirname + '/long-sample.csv', 'utf8');
var poisonedSampleRawCsv = fs.readFileSync(__dirname + '/poisoned-sample.csv', 'utf8');
var utf8BomSampleRawCsv = fs.readFileSync(__dirname + '/utf-8-bom-sample.csv', 'utf8');

function assertLongSampleParsedCorrectly(parsedCsv) {
Expand Down Expand Up @@ -298,4 +299,14 @@ describe('PapaParse', function() {
}
});
});

it('handles poisoned headers', function(done) {
Papa.parse(poisonedSampleRawCsv, {
header: true,
complete: function(parsedCsv) {
assert.deepEqual(parsedCsv.data[0], { ['__proto__']: 'X', toString: 'Y', valueOf: 'Z', __proto___1: 'A' });
done();
}
});
});
});
2 changes: 2 additions & 0 deletions tests/poisoned-sample.csv
@@ -0,0 +1,2 @@
__proto__,toString,valueOf,__proto__
X,Y,Z,A