Browse Source

changed empty lines test to treat escaped delimiters and quotes as content

pull/544/head
jaymeans 7 years ago
parent
commit
d9e08c4e25
  1. 9
      papaparse.js
  2. 22
      tests/test-cases.js

9
papaparse.js

@ -1075,13 +1075,8 @@
_input = ''; _input = '';
}; };
function testEmptyLine(s, d) { function testEmptyLine(s) {
var q = _config.quoteChar || '"'; return _config.skipEmptyLines === 'greedy' ? s.join('').trim() === '' : s.length === 1 && s[0].length === 0;
var r = _config.skipEmptyLines === 'greedy' ? new RegExp('^[' + escapeRegExp(d) + escapeRegExp(q) + '\\s]*$') : new RegExp('^$');
for (var i = 0; i < s.length; i++)
if (r.test(s[i]))
return true;
return false;
} }
function processResults() function processResults()

22
tests/test-cases.js

@ -1342,7 +1342,7 @@ var PARSE_TESTS = [
{ {
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",
input: 'a,b\n\n,\nc,d\n , \n""," "\n " " , " "\n,,,,\n",,,",","\n', input: 'a,b\n\n,\nc,d\n , \n""," "\n , \n,,,,\n',
config: { skipEmptyLines: 'greedy' }, config: { skipEmptyLines: 'greedy' },
expected: { expected: {
data: [['a', 'b'], ['c', 'd']], data: [['a', 'b'], ['c', 'd']],
@ -1350,22 +1350,12 @@ var PARSE_TESTS = [
} }
}, },
{ {
description: "Parsing with skipEmptyLines set to 'greedy' and regex special char as quoteChar", description: "Parsing with skipEmptyLines set to 'greedy' with quotes and delimiters as content",
notes: "Must skip lines correctly with reserved regex char as quoteChar", notes: "Must include lines with escaped delimiters and quotes",
input: 'a,b\n\n,\nc,d\n , \n]],] ]\n ] ] , ] ]\n,,,,\n],,,],],]\n', input: 'a,b\n\n,\nc,d\n" , ",","\n""" """,""""""\n\n\n',
config: { skipEmptyLines: 'greedy', quoteChar: ']' }, config: { skipEmptyLines: 'greedy' },
expected: {
data: [['a', 'b'], ['c', 'd']],
errors: []
}
},
{
description: "Parsing with skipEmptyLines set to 'greedy' and regex special char as delimiter",
notes: "Must skip lines correctly with reserved regex char as delimiter",
input: 'a]b\n\n]\nc]d\n ] \n""]" "\n " " ] " "\n]]]]\n"]]]"]"]"\n',
config: { skipEmptyLines: 'greedy', delimiter: ']' },
expected: { expected: {
data: [['a', 'b'], ['c', 'd']], data: [['a', 'b'], ['c', 'd'], [' , ', ','], ['" "', '""']],
errors: [] errors: []
} }
} }

Loading…
Cancel
Save