3

I have an HTML anchor link downloading a csv file. The problem I'm facing is that if there is a '#' symbol in the csv string (in the 'href' attribute) it is breaking the file at that point.

Is it breaking the file for some reason or is it reading it as the end of the file? I really don't know. I've tried escaping the character ('\#' instead of '#') but it just inputs the '\' and then breaks.

Thanks

****EDIT**** I am asking because I am trying to program this to work and am concerned that because certain fields may allow user input (hence, I cannot just avoid using '#') I may face this issue.

I am simply using html and a bit of javascript to create the string to download.

The '#' is breaking the file at that point. No new line, etc, everything after and including the '#' is not going into the file. I have viewed the file using Excel and also basic Notepad on windows. Thanks

****EDIT/EXAMPLE**** Sorry, the information is sensitive but I have included a simple example here.

This works fine:

<a class="download-link" download="test.csv" href="data:text/csv;charset=utf-8,col1h,col2h,col3h&#10;col1data,col2data,col3data">Downloads as expected</a>

This does not. Due to the '#' in 'col1data', the file, when downloaded, ends at 'col1datahasa'. The headers go in fine but everything after and including the '#' does not.

<a class="download-link" download="test.csv" href="data:text/csv;charset=utf-8,col1h,col2h,col3h&#10;col1datahasa#,col2datadontgetshown,col3datadontgetshown">Downloads with missing data</a>

If you copy the two links to a local file and run it you should see what I mean.

Mike
  • 254
  • 1
  • 6
  • 16
  • What do you mean by 'breaking' (line break, new column, just broken?) What software are you using to view the CSV File? Is this a programming questions or a general computing question? – JeffUK May 03 '19 at 10:56
  • 1
    If you have a problem with some code... it will help if we can see the /relevant/ bit of code... https://stackoverflow.com/help/mcve – JeffUK May 03 '19 at 11:10
  • @JeffUK I have edited again. If you copy the two links into a local file and run it in the browser you'll see what I mean. It's probably something simple that I'm missing but I'm just scratching my head right now and cannot find an answer. – Mike May 03 '19 at 11:31
  • https://stackoverflow.com/questions/5007352/how-to-escape-hash-character-in-url You have to use percent encoding, just tested and it works fine. Can't mark as duplicate as already flagged can someone else please? – JeffUK May 03 '19 at 11:50
  • 1
    I'll delete as clearly this has already been asked and answered on the link you have included – Mike May 03 '19 at 11:57

0 Answers0