Skip to content

Commit 47b356d

Browse files
jseterSergi Almacellas Abellana
jseter
authored and
Sergi Almacellas Abellana
committed
#727 update delimiter and newline index if they are earlier than the current position before tested. (#728)
1 parent 7ad8dda commit 47b356d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

papaparse.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,12 @@ License: MIT
15391539
continue;
15401540
}
15411541

1542+
if(nextDelim !== -1 && nextDelim < (quoteSearch + 1)) {
1543+
nextDelim = input.indexOf(delim, (quoteSearch + 1));
1544+
}
1545+
if(nextNewline !== -1 && nextNewline < (quoteSearch + 1)) {
1546+
nextNewline = input.indexOf(newline, (quoteSearch + 1));
1547+
}
15421548
// Check up to nextDelim or nextNewline, whichever is closest
15431549
var checkUpTo = nextNewline === -1 ? nextDelim : Math.min(nextDelim, nextNewline);
15441550
var spacesBetweenQuoteAndDelimiter = extraSpaces(checkUpTo);

tests/test-cases.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,22 @@ var PARSE_TESTS = [
14641464
data: [['a', 'b'], ['c', 'd'], [' , ', ','], ['" "', '""']],
14651465
errors: []
14661466
}
1467+
},
1468+
{
1469+
description: "Quoted fields with spaces between closing quote and next delimiter and contains delimiter",
1470+
input: 'A,",B" ,C,D\nE,F,G,H',
1471+
expected: {
1472+
data: [['A', ',B', 'C', 'D'],['E', 'F', 'G', 'H']],
1473+
errors: []
1474+
}
1475+
},
1476+
{
1477+
description: "Quoted fields with spaces between closing quote and newline and contains newline",
1478+
input: 'a,b,"c\n" \nd,e,f',
1479+
expected: {
1480+
data: [['a', 'b', 'c\n'], ['d', 'e', 'f']],
1481+
errors: []
1482+
}
14671483
}
14681484
];
14691485

0 commit comments

Comments
 (0)