From 9446aa4f1852047601417f3a7a1893a5326a6491 Mon Sep 17 00:00:00 2001 From: Alex Arvanitidis Date: Wed, 23 Oct 2024 14:10:08 +0300 Subject: [PATCH] fix: csv export --- src/app/api/datasets/export/route.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/app/api/datasets/export/route.ts b/src/app/api/datasets/export/route.ts index dc83743..56aa7b1 100644 --- a/src/app/api/datasets/export/route.ts +++ b/src/app/api/datasets/export/route.ts @@ -29,14 +29,17 @@ function generateCSVFromData( return row[header.key]; }); }); - const resultRows = rowsIn2DArray - .map((row) => row.join(',')) - .map((row) => { - if (row.toString().includes(',')) { - return `"${row}"`; + const resultRows = rowsIn2DArray.map((rowValues) => { + const escapedRowValues = rowValues.map((value) => { + if (value.toString().includes(',')) { + return `"${value}"`; } - return row; + return value; }); + + return escapedRowValues.join(','); + }); + return [headerRow, ...resultRows].join('\n'); }