Skip to content

Commit

Permalink
mholt#727 update delimiter and newline index if they are earlier than…
Browse files Browse the repository at this point in the history
… the current position before tested.
  • Loading branch information
Jamie Seter committed Oct 23, 2019
1 parent e536351 commit 48d1864
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,12 @@ License: MIT
continue;
}

if(nextDelim !== -1 && nextDelim < (quoteSearch + 1)) {
nextDelim = input.indexOf(delim, (quoteSearch + 1));
}
if(nextNewline !== -1 && nextNewline < (quoteSearch + 1)) {
nextNewline = input.indexOf(newline, (quoteSearch + 1));
}
// Check up to nextDelim or nextNewline, whichever is closest
var checkUpTo = nextNewline === -1 ? nextDelim : Math.min(nextDelim, nextNewline);
var spacesBetweenQuoteAndDelimiter = extraSpaces(checkUpTo);
Expand Down
16 changes: 16 additions & 0 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,22 @@ var PARSE_TESTS = [
data: [['a', 'b'], ['c', 'd'], [' , ', ','], ['" "', '""']],
errors: []
}
},
{
description: "Quoted fields with spaces between closing quote and next delimiter and contains delimiter",
input: 'A,",B" ,C,D\nE,F,G,H',
expected: {
data: [['A', ',B', 'C', 'D'],['E', 'F', 'G', 'H']],
errors: []
}
},
{
description: "Quoted fields with spaces between closing quote and newline and contains newline",
input: 'a,b,"c\n" \nd,e,f',
expected: {
data: [['a', 'b', 'c\n'], ['d', 'e', 'f']],
errors: []
}
}
];

Expand Down

0 comments on commit 48d1864

Please sign in to comment.