Skip to content

Commit 6653259

Browse files
authored
Fix: replace every double quote (#15)
* Fix: replace every doublequote * Test: update fixtures to test multiple occurances
1 parent d772a61 commit 6653259

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

src/helpers/append-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const separatorOrLineBreak = (length, elementIdx, separator) => (
66
);
77

88
const escapeDoubleQuotesInsideElement = (element) => {
9-
const thisElement = element.replace('"', '""');
9+
const thisElement = element.replace(/"/g, '""');
1010

1111
return thisElement;
1212
};

src/modules/convert-array-of-arrays-to-csv.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// import { checkSpecialCharsAndEmpty } from '../helpers/check-special-chars-and-empty';
2-
31
import { appendElement } from '../helpers/append-element';
42

53
export const convertArrayOfArraysToCSV = (data, { header, separator }) => {

test/fixtures/data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const dataArray = [
99
];
1010

1111
const dataArrayWithDoubleQuotes = [
12-
[1, 'Mark', 'Ot"to', '@mdo'],
12+
[1, 'Mark', 'Ot"t"o', '@mdo'],
1313
[2, 'Jacob', 'Thornton', '@fat'],
1414
[3, 'Larry', 'the Bird', '@twitter'],
1515
];
@@ -51,7 +51,7 @@ const dataObjectWithDoubleQuotes = [
5151
{
5252
number: 1,
5353
first: 'Mark',
54-
last: 'Ot"to',
54+
last: 'Ot"t"o',
5555
handle: '@mdo',
5656
},
5757
{

test/fixtures/expected-results.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const expectedResultObjecOnlySeparatorTab = 'number\tfirst\tlast\thandle\
1616

1717
export const expectedResultArrayHeaderWithSpaces = '"number number",first,last,handle\n1,Mark,Otto,@mdo\n2,Jacob,Thornton,@fat\n3,Larry,"the Bird",@twitter\n';
1818

19-
export const expectedResultArrayWithDoubleQoutesInsideElement = '1,Mark,"Ot""to",@mdo\n2,Jacob,Thornton,@fat\n3,Larry,"the Bird",@twitter\n';
19+
export const expectedResultArrayWithDoubleQoutesInsideElement = '1,Mark,"Ot""t""o",@mdo\n2,Jacob,Thornton,@fat\n3,Larry,"the Bird",@twitter\n';
2020

2121
export const expectedResultArrayWithHeaderNoOptions = expectedResultObjectNoOptions;
2222

0 commit comments

Comments
 (0)