Skip to content
Snippets Groups Projects
Commit 9e800596 authored by Julia Friesel's avatar Julia Friesel
Browse files

Handle special characters in strings

parent f8007fac
No related branches found
No related tags found
No related merge requests found
......@@ -64,7 +64,8 @@ function transformToCsv(cycleDays) {
const rows = cycleDays
.map(day => {
return columnNames.map(column => {
return objectPath.get(day, column, '')
const val = objectPath.get(day, column, '')
return typeof val === 'string' ? csvify(val) : val
})
})
.map(row => row.join(','))
......@@ -72,3 +73,20 @@ function transformToCsv(cycleDays) {
rows.unshift(columnNames.join(','))
return rows.join('\n')
}
function csvify (val) {
// escape double quotes
val = val.replace(/"/g, '""')
val = val.toLowerCase()
const hasSpecialChars = (
val.includes('\n') ||
val.includes('\t') ||
val.includes(',') ||
val.includes(';') ||
val.includes('.') ||
val.includes('\'')
)
return hasSpecialChars ? `"${val}"` : val
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment