react-csv-to-table
react-csv-to-table copied to clipboard
csvDelimiter Contained within Double Quotes Still Recognized as Delimiter
My data looks like:
58,0::0::14,0::0::18,"['Table', 'Food']"
442,0::0::18,0::0::26,"['Table', 'Food']"
665,0::0::27,0::0::52,"['Food', 'Table', 'Shelf']"
I believe this is valid CSV and that the final column should be recognized as 1 column because of the double quotes, but this library is splitting the last column into multiple columns when using the comma as a delimiter because of its presence within the last column.
<CsvToHtmlTable
data={this.state.csvData}
csvDelimiter=","
/>
Same here. I believe too that this is valid CSV. Right now I use a nasty workaround to replace the comma delimiter with the four spaces delimiter** and then remove the quotes before passing the data, which is bad no matter how you look at it:
data.replace(/(,)(?=(?:[^"]|"[^"]*")*$)/g, " ").replace(/"/g, '')
** It seemed to me like the safest delimiter to use in regard to how (un)likely it is for someone to use it as actual content.
The code just does a simple .split
with the configured delimiter. Suggest changing it to use a proper CSV parser that handles quotes, e.g. d3.csvParse.
I'm hitting this as well. Hope the PR can be accepted soon!