From d9e08c4e25d7609a96842910a77a88d955a6bbe3 Mon Sep 17 00:00:00 2001 From: jaymeans Date: Fri, 27 Jul 2018 17:25:47 -0700 Subject: [PATCH] changed empty lines test to treat escaped delimiters and quotes as content --- papaparse.js | 9 ++------- tests/test-cases.js | 22 ++++++---------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/papaparse.js b/papaparse.js index c7e4bbc..b2ef8d8 100755 --- a/papaparse.js +++ b/papaparse.js @@ -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() diff --git a/tests/test-cases.js b/tests/test-cases.js index c03ff5c..be5cc5a 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -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 = [ } }, { - 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: [] } }