From 48d186429d0c25844827f2bc6ce2f6e6161f78bf Mon Sep 17 00:00:00 2001 From: Jamie Seter Date: Wed, 23 Oct 2019 15:14:34 -0400 Subject: [PATCH] #727 update delimiter and newline index if they are earlier than the current position before tested. --- papaparse.js | 6 ++++++ tests/test-cases.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/papaparse.js b/papaparse.js index 94317709..e8aeb190 100755 --- a/papaparse.js +++ b/papaparse.js @@ -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); diff --git a/tests/test-cases.js b/tests/test-cases.js index 58a85f08..0b9c205d 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -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: [] + } } ];