Browse Source

Bugfix: Resolve parsing issue when first field is empty and unquoted

pull/696/head
David Boskovic 6 years ago
parent
commit
3978d24ed4
  1. 3
      papaparse.js
  2. 8
      tests/test-cases.js

3
papaparse.js

@ -1606,9 +1606,8 @@ License: MIT @@ -1606,9 +1606,8 @@ License: MIT
if (quoteSearch !== -1) {
// we have quotes, so we try to find the next delimiter not enclosed in quotes and also next starting quote char
var nextDelimObj = getNextUnqotedDelimiter(nextDelim, quoteSearch, nextNewline);
// if we have next delimiter char which is not enclosed in quotes
if (nextDelimObj && nextDelimObj.nextDelim) {
if (nextDelimObj && typeof nextDelimObj.nextDelim !== 'undefined') {
nextDelim = nextDelimObj.nextDelim;
quoteSearch = nextDelimObj.quoteSearch;
row.push(input.substring(cursor, nextDelim));

8
tests/test-cases.js

@ -323,6 +323,14 @@ var CORE_PARSER_TESTS = [ @@ -323,6 +323,14 @@ var CORE_PARSER_TESTS = [
errors: []
}
},
{
description: "Line starts with unquoted empty field",
input: ',b,c\n"d",e,f',
expected: {
data: [['', 'b', 'c'], ['d', 'e', 'f']],
errors: []
}
},
{
description: "Line ends with quoted field",
input: 'a,b,c\nd,e,f\n"g","h","i"\n"j","k","l"',

Loading…
Cancel
Save