mui-datatables
mui-datatables copied to clipboard
Download CSV option not properly removing line breaks from string
When users download CSV, fields with \r OR \n line breaks are not properly escaped, causing the CSV dataset to be messed up.
Expected Behavior
CSV fields should properly account for line breaks within strings.
Current Behavior
CSV fields are not accounting for line breaks, forcing a new line whenever a \r OR \n is seen.
Upon looking at the source file. It appears the right place to fix this issue is in line 30 under utils.js
const replaceDoubleQuoteInString = columnData =>
typeof columnData === 'string' ? columnData.replace(/\"/g, '""') : columnData;
this should be
const replaceDoubleQuoteInString = columnData =>
typeof columnData === 'string' ? columnData.replace(/\"/g, '""').replace(/\n|\r/g, "") : columnData;