1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-08 21:10:05 +00:00

fix: removed extra slash + added tests

This commit is contained in:
Saad Jutt
2021-05-07 05:26:08 +05:00
parent 80e5de5d65
commit 88f08e8864
2 changed files with 103 additions and 6 deletions

View File

@@ -71,15 +71,19 @@ export const convertToCSV = (data: any) => {
let value
const currentCell = row[fieldName]
// stringify with replacer converts null values to empty strings
// also wraps the value in double quotes
value = JSON.stringify(currentCell, replacer).replace(/\\\"/g, `""`)
if (typeof currentCell === 'number') return currentCell
value = value.replace(/\\\\/gm, '\\')
// stringify with replacer converts null values to empty strings
value = currentCell === null ? '' : currentCell
// if there any present, it should have preceding (") for escaping
value = value.replace(/"/g, `""`)
// also wraps the value in double quotes
value = `"${value}"`
if (
value.substring(1, value.length - 1).search(/(\\t|\\n|\\r|,|\'|\")/gm) <
0
value.substring(1, value.length - 1).search(/(\t|\n|\r|,|\'|\")/gm) < 0
) {
// Remove wrapping quotes for values that don't contain special characters
value = value.substring(1, value.length - 1)