DataTable 'csv' button isn't properly escaping double quotation marks

DataTable 'csv' button isn't properly escaping double quotation marks

stevevancestevevance Posts: 58Questions: 6Answers: 1
edited October 2015 in Free community support

I am showing building permits in a table, and many of them have double quotation marks around phrases (the phrases that will be printed on illuminated signs). DataTables is only escaping the first double quotation mark, and not the subsequent marks.

I am using the default exportOptions

See the CSV output, looking for the word "panda" in the "Work Description" column:

"Permit Type","Address","Issue Date","Issue Date (actual)","Est. Cost","Work Description","Latitude","Longitude","Permit ID"
"Signs","180 N Wabash Ave","09/30/2015","09/30/2015","$4,200.00","East elevation: led illuminated wall sign cabinet \"panda express" sign will be installed into the window mullion, sign will be flush mounted & will not be on the public way.","41.88535370","-87.62641328","100590582"
"Signs","180 N Wabash Ave","09/30/2015","09/30/2015","$4,200.00","North elevation: led illuminated wall sign cabinet \"panda express" sign will be installed into the window mullion, sign will be flush mounted & will not be on the public way.","41.88535370","-87.62641328","100590583"
"Electric wiring","180 N Wabash Ave","09/22/2015","09/22/2015","$500.00","Voice data wiring at panda express space","41.88535370","-87.62641328","100615241"

I have set up a workaround for the time being, replacing the double quotation marks with single marks.

return row.properties.work_description.replace(/"/g,'\'');

Is there a bug in DataTables button?

Replies

  • tangerinetangerine Posts: 3,356Questions: 37Answers: 394

    If your data includes pairs of double quotation marks, then of course you cannot use double quotation marks as a field delimiter. That has nothing to do with DataTables, it is just routine CSV requirements.

  • allanallan Posts: 62,290Questions: 1Answers: 10,214 Site admin

    Hi,

    The escaping of only the first character was fixed with this issue. I'll be making a new release with the required changes shortly.

    Regarding the use of double quotes - you can actually do this, but weirdly the RFC for this states that you should escape it with another double quote... The next release of Buttons will confirm to that standard - discussion and commit here.

    The nightly version of Buttons has these fixes already.

    Allan

  • stevevancestevevance Posts: 58Questions: 6Answers: 1

    Thanks for the response!
    My workaround is an acceptable one for my data because there's no difference in the text between a phrase surrounded by double quotation marks and the same phrase surrounded by single quotation marks.

This discussion has been closed.