Compare commits

...

3 Commits
master ... 4.x

Author SHA1 Message Date
Sergi Almacellas Abellana 8b663aa17e Patch version bump 6 years ago
Sergi Almacellas Abellana 8af1d23646 Correctly guess deliminter when mixed with commas 6 years ago
Chris Zubak-Skees 886fdf3cb2 Consistently apply regex escaping to quoteChar (#602) 6 years ago
  1. 2
      package.json
  2. 10
      papaparse.js
  3. 4
      papaparse.min.js
  4. 28
      tests/test-cases.js

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "papaparse", "name": "papaparse",
"version": "4.6.2", "version": "4.6.3",
"description": "Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.", "description": "Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.",
"keywords": [ "keywords": [
"csv", "csv",

10
papaparse.js

@ -1,6 +1,6 @@
/* @license /* @license
Papa Parse Papa Parse
v4.6.2 v4.6.3
https://github.com/mholt/PapaParse https://github.com/mholt/PapaParse
License: MIT License: MIT
*/ */
@ -296,7 +296,7 @@ if (!Array.isArray)
unpackConfig(); unpackConfig();
var quoteCharRegex = new RegExp(_quoteChar, 'g'); var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), 'g');
if (typeof _input === 'string') if (typeof _input === 'string')
_input = JSON.parse(_input); _input = JSON.parse(_input);
@ -1266,7 +1266,7 @@ if (!Array.isArray)
if (typeof fieldCountPrevRow === 'undefined') if (typeof fieldCountPrevRow === 'undefined')
{ {
fieldCountPrevRow = fieldCount; fieldCountPrevRow = 0;
continue; continue;
} }
else if (fieldCount > 1) else if (fieldCount > 1)
@ -1279,7 +1279,7 @@ if (!Array.isArray)
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;
@ -1438,7 +1438,7 @@ if (!Array.isArray)
var nextDelim = input.indexOf(delim, cursor); var nextDelim = input.indexOf(delim, cursor);
var nextNewline = input.indexOf(newline, cursor); var nextNewline = input.indexOf(newline, cursor);
var quoteCharRegex = new RegExp(escapeChar.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&') + quoteChar, 'g'); var quoteCharRegex = new RegExp(escapeRegExp(escapeChar) + escapeRegExp(quoteChar), 'g');
var quoteSearch; var quoteSearch;
// Parser loop // Parser loop

4
papaparse.min.js vendored

File diff suppressed because one or more lines are too long

28
tests/test-cases.js

@ -1159,6 +1159,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",
@ -1324,7 +1334,7 @@ var PARSE_TESTS = [
} }
}, },
{ {
description: "Using reserved regex characters as quote characters", description: "Using reserved regex character . as quote character",
input: '.a\na.,b\r\nc,d\r\ne,f\r\ng,h\r\ni,j', input: '.a\na.,b\r\nc,d\r\ne,f\r\ng,h\r\ni,j',
config: { quoteChar: '.' }, config: { quoteChar: '.' },
expected: { expected: {
@ -1339,6 +1349,22 @@ var PARSE_TESTS = [
} }
} }
}, },
{
description: "Using reserved regex character | as quote character",
input: '|a\na|,b\r\nc,d\r\ne,f\r\ng,h\r\ni,j',
config: { quoteChar: '|' },
expected: {
data: [['a\na', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h'], ['i', 'j']],
errors: [],
meta: {
linebreak: '\r\n',
delimiter: ',',
cursor: 27,
aborted: false,
truncated: false
}
}
},
{ {
description: "Parsing with skipEmptyLines set to 'greedy'", description: "Parsing with skipEmptyLines set to 'greedy'",
notes: "Must parse correctly without lines with no content", notes: "Must parse correctly without lines with no content",

Loading…
Cancel
Save