react-csv-to-table icon indicating copy to clipboard operation
react-csv-to-table copied to clipboard

csvDelimiter Contained within Double Quotes Still Recognized as Delimiter

Open sambshapiro opened this issue 5 years ago • 3 comments

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=","
/>

sambshapiro avatar Feb 20 '20 19:02 sambshapiro

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.

gsarig avatar May 13 '20 11:05 gsarig

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.

nedgar avatar Jan 27 '21 17:01 nedgar

I'm hitting this as well. Hope the PR can be accepted soon!

nk9 avatar Oct 31 '22 15:10 nk9