Browse Source

Correctly guess deliminter when mixed with commas

Closes #592
pull/622/head
Sergi Almacellas Abellana 6 years ago
parent
commit
f6b1b36c3f
  1. 4
      papaparse.js
  2. 10
      tests/test-cases.js

4
papaparse.js

@ -1245,7 +1245,7 @@ License: MIT
if (typeof fieldCountPrevRow === 'undefined') if (typeof fieldCountPrevRow === 'undefined')
{ {
fieldCountPrevRow = fieldCount; fieldCountPrevRow = 0;
continue; continue;
} }
else if (fieldCount > 1) else if (fieldCount > 1)
@ -1258,7 +1258,7 @@ License: MIT
if (preview.data.length > 0) if (preview.data.length > 0)
avgFieldCount /= (preview.data.length - emptyLinesCount); avgFieldCount /= (preview.data.length - emptyLinesCount);
if ((typeof bestDelta === 'undefined' || delta < bestDelta) if ((typeof bestDelta === 'undefined' || delta > bestDelta)
&& avgFieldCount > 1.99) && avgFieldCount > 1.99)
{ {
bestDelta = delta; bestDelta = delta;

10
tests/test-cases.js

@ -1193,6 +1193,16 @@ var PARSE_TESTS = [
errors: [] errors: []
} }
}, },
{
description: "Pipe delimiter is guessed correctly when mixed with comas",
notes: "Guessing the delimiter should work even if there are many lines of comments at the start of the file",
input: 'one|two,two|three\nfour|five,five|six',
config: {},
expected: {
data: [['one','two,two','three'],['four','five,five','six']],
errors: []
}
},
{ {
description: "Single quote as quote character", description: "Single quote as quote character",
notes: "Must parse correctly when single quote is specified as a quote character", notes: "Must parse correctly when single quote is specified as a quote character",

Loading…
Cancel
Save