From a74c9466c6e935ec85726dc4bf1b05d94d39152b Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Fri, 18 Dec 2020 19:20:57 +0100 Subject: [PATCH] Escape CSV data --- src/app/services/download.service.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/services/download.service.ts b/src/app/services/download.service.ts index 0c13604..7ff1521 100644 --- a/src/app/services/download.service.ts +++ b/src/app/services/download.service.ts @@ -24,13 +24,19 @@ export class DownloadService { const newRow = columnInfo.map((column) => { let cellData = row[column.dataPath]; if (Array.isArray(cellData)) { - cellData = cellData.join(', '); + cellData = cellData.join('", "'); } else if (column.type === 'NumRange') { - cellData = (row[column.dataPath + ".min"] || '') + " bis " + (row[column.dataPath + ".max"] || ''); + cellData = + (row[column.dataPath + '.min'] || '') + + ' bis ' + + (row[column.dataPath + '.max'] || ''); } else if (column.type === 'DateRange') { - cellData = (row[column.dataPath + ".from"] || '') + " bis " + (row[column.dataPath + ".to"] || ''); + cellData = + (row[column.dataPath + '.from'] || '') + + ' bis ' + + (row[column.dataPath + '.to'] || ''); } - return JSON.stringify(cellData || ''); + return '"' + (cellData ?? '').toString().replace(/"/g, "''") + '"'; }); csvData.push(newRow.join(this.csvChar)); }