mui-datatables icon indicating copy to clipboard operation
mui-datatables copied to clipboard

Download CSV option not properly removing line breaks from string

Open alcmacys opened this issue 7 years ago • 1 comments

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.

alcmacys avatar Feb 27 '19 20:02 alcmacys

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;

alcmacys avatar Feb 27 '19 20:02 alcmacys