New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid double-encoding file:/// urls #971
base: dev
Are you sure you want to change the base?
Conversation
I'm very sorry for not thinking about that, but thank you so much for the fix! :) On looking up a bit and with some experimentation, I found this test to check if a URL is already encoded. if (decodeURIComponent(string) === string) {
// we can encode it
} It will skip URLs that do not need encoding. And will also encode file:/// URLs that weren't encoded! Unless you disagree, it would be cool if you could include this! |
@dannywritescode That sounds good, |
Added a provision for relative path local |
Hi can you confirm if this fixes the issue described in #1039 with foreign characters? |
@JeffreyCA I just tested and it works with this fix but only if you encode the url yourself before passing it to Tone. I'm going to add another check that should make pre-encoding unnecessary. I think the issue is that in many cases the browser automatically encodes a url when you do |
What do you all think of removing all of the url handling stuff altogether? I think there used to be more of a reason to enable multiple file extensions, but i think at this point maybe it's not as useful a feature and is just getting in the way more than it's helping? If we removed all of the URL modifying code, we could just require that the user escape the url string they pass @marcelblum what do you think? i appreciate all of the work that you've done fixing this feature |
@tambien I'd be fine with that, TBH prior to #902 in my own use of Tone.js I had gotten into the habit of always pre-encoding all urls I passed to Tone functions. And the current url handling is certainly getting a tad messy. That said, it seems like a really common issue for other Tone.js users to run into trying to pass filenames like "C#2.wav" and getting errors because they expect Tone to handle url encoding automatically, and it is a nice-to-have if Tone handled that automatically. Just trying to make everyone happy 😃 |
Me too, I think supporting both scenarios with a flag mechanism like @marcelblum mentioned would work well too. |
I agree, the current URL handling has quite some side-effects that I didn't see. I think the problem is that it encodes all characters by default, and then excludes those (like Since we only really need to encode the The I understand if we don't want any URL handling at all though, as that is more transparent. I think there is value in supporting the hash symbol out of the box (sharps seem to be more commonly used in file names, as if it's an informal standard, and some DAW software like FL Studio also use sharps when exporting notes). I'm also happy with the idea of using a flag! |
I have raised a new issue #1097 related to the same problem. I think the trick of |
#902 introduced a breaking change in that the file loader now assumes a given URL is unencoded. This is probably fine in most use cases but when loading local files using the file:/ scheme the url is already encoded.
(A more complete solution might be to add a flag somewhere so the user can specify if they know the url being passed to Tone is already encoded, to avoid double-encoding. But I figured a simple check for
startsWith("file:/")
is best for now to avoid an overly-complex solution unless it affects other users in more exotic scenarios other than just file:///.)