rndme / download

file downloading using client-side javascript
MIT License
2.29k stars 418 forks source link

TXT URL not working with RELATIVE PATH #92

Closed daidaiworm closed 1 year ago

daidaiworm commented 5 years ago

tried both download.js version4.2 and version4.21.

My intention was to download a linked txt file. For some reason I can't specific absolute address, such as http://foobar.com/path/txtfile.txt What I can do is to give a relative address, like "./path1/path2/txtfile.txt"

It's ok to run download(txtfile.txt) or http://foobar.com/path/txtfile.txt

But when run download(./txtfile.txt) or ../path/txtfile.txt The txtfile.txt didn't get downloaded. What we get is just a file with contains the string only, for this case you get "../path/txtfile.txt"

bezzil85 commented 4 years ago

same problem, any soluton around ? Somehow instead of original text inside txt file, we get url from where it was downloaded

rndme commented 1 year ago

When passing just 1 arguments, the path gets validated to sniff between urls and arbitrary text content that should be downloaded with a generated file name. Leading dots in a url will break this detection because it looks for the given path appearing in a fully qualified path, and the fully qualified path doesn't contain the leading ".". This would be hard to patch without breaking existing workflows. I would suggest you normalize the url before passing to download(), here's a helper function to do that:

function normalize(path){
  var a = document.createElement("a");
  a.href=path;
  return a.href;
}