highcharts / export-csv

Highcharts plugin to export chart data to CSV
http://www.highcharts.com/plugin-registry/single/7/Export-CSV
MIT License
76 stars 94 forks source link

Download CSV breaks for '#' chars in Firefox #85

Open aarose opened 8 years ago

aarose commented 8 years ago

To reproduce:

  1. Open Firefox
  2. Go to http://jsfiddle.net/cqjvD/1069/ (or any export-csv enabled chart with a series that has the "#" character in the name)
  3. Click "Download CSV" from the drop-down menu
  4. Examine the CSV - the data is blank

    Source:

The source of this issue seems to be in Highcharts.Chart.prototype.downloadCSV, when passing 'data:text/csv,' + csv.replace(/\n/g, '%0A'), as the href param.

Proposed solution:

Add .replace(/#/g, '%23') to encode the "#" character. Encoding the string could also be passed off to a new function that could encode all the special characters at once, not just newlines and "#".