diff --git a/papaparse.js b/papaparse.js index 7febbaf..0b15bfc 100755 --- a/papaparse.js +++ b/papaparse.js @@ -1245,7 +1245,7 @@ License: MIT if (typeof fieldCountPrevRow === 'undefined') { - fieldCountPrevRow = fieldCount; + fieldCountPrevRow = 0; continue; } else if (fieldCount > 1) @@ -1258,7 +1258,7 @@ License: MIT if (preview.data.length > 0) avgFieldCount /= (preview.data.length - emptyLinesCount); - if ((typeof bestDelta === 'undefined' || delta < bestDelta) + if ((typeof bestDelta === 'undefined' || delta > bestDelta) && avgFieldCount > 1.99) { bestDelta = delta; diff --git a/tests/test-cases.js b/tests/test-cases.js index 2e19d68..1dceaa3 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -1193,6 +1193,16 @@ var PARSE_TESTS = [ 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", notes: "Must parse correctly when single quote is specified as a quote character",