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 @@ @@ -1075,13 +1075,8 @@
_input = '';
};
function testEmptyLine(s, d) {
var q = _config.quoteChar || '"';
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 testEmptyLine(s) {
return _config.skipEmptyLines === 'greedy' ? s.join('').trim() === '' : s.length === 1 && s[0].length === 0;
}
function processResults()

22
tests/test-cases.js

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

Loading…
Cancel
Save