Browse Source

adding tests and fix for reserved regex chars as quoteChar and delimiter

pull/544/head
jaymeans 7 years ago committed by jaymeans
parent
commit
19afbbfbe4
  1. 8
      papaparse.js
  2. 20
      tests/test-cases.js

8
papaparse.js

@ -1077,7 +1077,9 @@ @@ -1077,7 +1077,9 @@
function testEmptyLine(s, d) {
var q = _config.quoteChar || '"';
var r = _config.skipNoContentLines ? new RegExp('^[' + d + q + '\\s]*$') : new RegExp('^$');
var r = _config.skipNoContentLines ? new RegExp('^[' + escapeRegExp(d) + escapeRegExp(q) + '\\s]*$') : new RegExp('^$');
// var q = _config.quoteChar || '"';
// var r = _config.skipNoContentLines ? new RegExp('^[' + d + q + '\\s]*$') : new RegExp('^$');
for (var i = 0; i < s.length; i++)
if (r.test(s[i]))
return true;
@ -1300,8 +1302,8 @@ @@ -1300,8 +1302,8 @@
}
}
/** https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions */
function escapeRegExp(string) {
function escapeRegExp(string)
{
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}

20
tests/test-cases.js

@ -1358,6 +1358,26 @@ var PARSE_TESTS = [ @@ -1358,6 +1358,26 @@ var PARSE_TESTS = [
data: [['a', 'b'], ['c', 'd']],
errors: []
}
},
{
description: "Parsing with skipNoContentLines 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: { skipNoContentLines: true, quoteChar: ']' },
expected: {
data: [['a', 'b'], ['c', 'd']],
errors: []
}
},
{
description: "Parsing with skipNoContentLines 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: { skipNoContentLines: true, delimiter: ']' },
expected: {
data: [['a', 'b'], ['c', 'd']],
errors: []
}
}
];

Loading…
Cancel
Save