Skip to content

Commit

Permalink
Consistently apply regex escaping to quoteChar (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriszs authored and pokoli committed Dec 2, 2018
1 parent ae98248 commit 9a541b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions papaparse.js
Expand Up @@ -278,7 +278,7 @@ License: MIT

unpackConfig();

var quoteCharRegex = new RegExp(_quoteChar, 'g');
var quoteCharRegex = new RegExp(escapeRegExp(_quoteChar), 'g');

if (typeof _input === 'string')
_input = JSON.parse(_input);
Expand Down Expand Up @@ -1417,7 +1417,7 @@ License: MIT

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
Expand Down
18 changes: 17 additions & 1 deletion tests/test-cases.js
Expand Up @@ -1358,7 +1358,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: {
Expand All @@ -1373,6 +1373,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",
Expand Down

0 comments on commit 9a541b1

Please sign in to comment.