diff --git a/papaparse.js b/papaparse.js index c8b5efa..6506565 100755 --- a/papaparse.js +++ b/papaparse.js @@ -990,7 +990,15 @@ return; for (var i = 0; needsHeaderRow() && i < _results.data.length; i++) for (var j = 0; j < _results.data[i].length; j++) - _fields.push(_results.data[i][j]); + { + var header = _results.data[i][j]; + + if (_config.trimHeaders) { + header = header.trim(); + } + + _fields.push(header); + } _results.data.splice(0, 1); } diff --git a/tests/test-cases.js b/tests/test-cases.js index 109a3b3..fc21635 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -713,6 +713,15 @@ var PARSE_TESTS = [ errors: [] } }, + { + description: "Header row with whitespace trimmed", + input: ' A , B , C \r\na,b,c', + config: { header: true, trimHeaders: true }, + expected: { + data: [{"A": "a", "B": "b", "C": "c"}], + errors: [] + } + }, { description: "Tab delimiter", input: 'a\tb\tc\r\nd\te\tf',