diff --git a/src/cli-ux/styled/table.ts b/src/cli-ux/styled/table.ts index 1db3ba04a..c7087533a 100644 --- a/src/cli-ux/styled/table.ts +++ b/src/cli-ux/styled/table.ts @@ -150,7 +150,7 @@ class Table> { const lineToBeEscaped = values.find( (e: string) => e.includes('"') || e.includes('\n') || e.includes('\r\n') || e.includes('\r') || e.includes(','), ) - return values.map((e) => (lineToBeEscaped ? `"${e.replace('"', '""')}"` : e)) + return values.map((e) => (lineToBeEscaped ? `"${e.replaceAll('"', '""')}"` : e)) } private outputCSV() { diff --git a/test/cli-ux/styled/table.test.ts b/test/cli-ux/styled/table.test.ts index 15058461c..c32ef23c3 100644 --- a/test/cli-ux/styled/table.test.ts +++ b/test/cli-ux/styled/table.test.ts @@ -158,13 +158,17 @@ describe('styled/table', () => { id: '12"3', name: 'supertable-test-2', }, + { + id: '1"2"3', + name: 'supertable-test-3', + }, { id: '123', - name: 'supertable-test-3,comma', + name: 'supertable-test-4,comma', }, { id: '123', - name: 'supertable-test-4', + name: 'supertable-test-5', }, ], columns, @@ -173,8 +177,9 @@ describe('styled/table', () => { expect(output.stdout).to.equal(`ID,Name "123\n2","supertable-test-1" "12""3","supertable-test-2" -"123","supertable-test-3,comma" -123,supertable-test-4\n`) +"1""2""3","supertable-test-3" +"123","supertable-test-4,comma" +123,supertable-test-5\n`) }) fancy.stdout().end('outputs in csv without headers', (output) => {