Browse Source

Consistently apply regex escaping to quoteChar (#602)

4.x
Chris Zubak-Skees 6 years ago committed by Sergi Almacellas Abellana
parent
commit
886fdf3cb2
  1. 4
      papaparse.js
  2. 18
      tests/test-cases.js

4
papaparse.js

@ -296,7 +296,7 @@ if (!Array.isArray) @@ -296,7 +296,7 @@ if (!Array.isArray)
unpackConfig();
var quoteCharRegex = new RegExp(_quoteChar, 'g');
var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), 'g');
if (typeof _input === 'string')
_input = JSON.parse(_input);
@ -1438,7 +1438,7 @@ if (!Array.isArray) @@ -1438,7 +1438,7 @@ if (!Array.isArray)
var nextDelim = input.indexOf(delim, 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;
// Parser loop

18
tests/test-cases.js

@ -1324,7 +1324,7 @@ var PARSE_TESTS = [ @@ -1324,7 +1324,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',
config: { quoteChar: '.' },
expected: {
@ -1339,6 +1339,22 @@ var PARSE_TESTS = [ @@ -1339,6 +1339,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'",
notes: "Must parse correctly without lines with no content",

Loading…
Cancel
Save