Skip to content

Commit 23e1b47

Browse files
authored
- fixes multi-character delimiter with quoted field issue (#879)
1 parent a6fdfcb commit 23e1b47

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Diff for: docs/docs.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ <h5>Unparse Config Options</h5>
303303
<code>delimiter</code>
304304
</td>
305305
<td>
306-
The delimiting character. It must not be found in <a href="#readonly">Papa.BAD_DELIMITERS</a>.
306+
The delimiting character. Multi-character delimiters are supported. It must not be found in <a href="#readonly">Papa.BAD_DELIMITERS</a>.
307307
</td>
308308
</tr>
309309
<tr>
@@ -470,7 +470,7 @@ <h5 id="config-details">Config Options</h5>
470470
<code>delimiter</code>
471471
</td>
472472
<td>
473-
The delimiting character. Leave blank to auto-detect from a list of most common delimiters, or any values passed in through <code>delimitersToGuess</code>. It can be a string or a function. If string, it must be one of length 1. If a function, it must accept the input as first parameter and it must return a string which will be used as delimiter. In both cases it cannot be found in <a href="#readonly">Papa.BAD_DELIMITERS</a>.
473+
The delimiting character. Leave blank to auto-detect from a list of most common delimiters, or any values passed in through <code>delimitersToGuess</code>. It can be a string or a function. If a string, it can be of any length (so multi-character delimiters are supported). If a function, it must accept the input as first parameter and it must return a string which will be used as delimiter. In both cases it cannot be found in <a href="#readonly">Papa.BAD_DELIMITERS</a>.
474474
</td>
475475
</tr>
476476
<tr>
@@ -861,7 +861,7 @@ <h5 id="readonly">Read-Only</h5>
861861
<tr>
862862
<td><code>Papa.BAD_DELIMITERS</code></td>
863863
<td>
864-
An array of characters that are not allowed as delimiters.
864+
An array of characters that are not allowed as delimiters (<code>\r, \n, ", \ufeff</code>).
865865
</td>
866866
</tr>
867867
<tr>

Diff for: papaparse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ License: MIT
15551555
var spacesBetweenQuoteAndDelimiter = extraSpaces(checkUpTo);
15561556

15571557
// Closing quote followed by delimiter or 'unnecessary spaces + delimiter'
1558-
if (input[quoteSearch + 1 + spacesBetweenQuoteAndDelimiter] === delim)
1558+
if (input.substr(quoteSearch + 1 + spacesBetweenQuoteAndDelimiter, delimLen) === delim)
15591559
{
15601560
row.push(input.substring(cursor, quoteSearch).replace(quoteCharRegex, quoteChar));
15611561
cursor = quoteSearch + 1 + spacesBetweenQuoteAndDelimiter + delimLen;

Diff for: tests/test-cases.js

+16
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,16 @@ var PARSE_TESTS = [
847847
errors: []
848848
}
849849
},
850+
{
851+
description: "Multi-character delimiter (length 2) with quoted field",
852+
input: 'a, b, "c, e", d',
853+
config: { delimiter: ", " },
854+
notes: "The quotes must be immediately adjacent to the delimiter to indicate a quoted field",
855+
expected: {
856+
data: [['a', 'b', 'c, e', 'd']],
857+
errors: []
858+
}
859+
},
850860
{
851861
description: "Callback delimiter",
852862
input: 'a$ b$ c',
@@ -1713,6 +1723,12 @@ var UNPARSE_TESTS = [
17131723
config: { delimiter: ', ' },
17141724
expected: 'A, b, c\r\nd, e, f'
17151725
},
1726+
{
1727+
description: "Custom delimiter (Multi-character), field contains custom delimiter",
1728+
input: [['A', 'b', 'c'], ['d', 'e', 'f, g']],
1729+
config: { delimiter: ', ' },
1730+
expected: 'A, b, c\r\nd, e, "f, g"'
1731+
},
17161732
{
17171733
description: "Bad delimiter (\\n)",
17181734
notes: "Should default to comma",

0 commit comments

Comments
 (0)