-
Notifications
You must be signed in to change notification settings - Fork 571
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
Fixed safe uri alphabet (+$ -> _.) for compressToEncodedURIComponent/decompressToEncodedURIComponent #127
base: master
Are you sure you want to change the base?
Conversation
Thanks, this is a known issue but we cannot merge this unfortunately :( The problem is that we cannot change this without breaking backwards compatibility. (also, definitely something to remember if we ever go through a "spec" change - see #122) |
While I agree we should do this, this is a breaking change and will break havoc all over the place. So we either reject it or we create another method... |
I propose two new methods...
With "URI Safe" being the "Unreserved" characters defined in RFC 3986 as discussed here... https://joshbuchea.com/uri-safe-characters/ ...but excluding the tilde character '~' for historical reasons due to RFC 1738 as discussed here... https://jkorpela.fi/tilde.html I think that naming the methods the way I suggest above makes it clearer what the method is actually doing. As "URI Safe" can be thought of as a character encoding like "UTF-16" so the new method naming should parallel the existing naming (i.e. Possible alternate (but longer) method names if the ones suggested above aren't acceptable:
etc... |
I just came across something called Base64URL which is described in Section 5 of RFC 4648 back in 2006... https://www.rfc-editor.org/rfc/rfc4648#section-10 ...and explained in more detail on this website... https://base64.guru/standards/base64url Base64URL is addressing the same problem with regards to Base64 encoded strings containing characters that aren't allowed in URLs. In short, it's the same algorithm as Base64 except for these 4 changes:
I feel that the new compressToURISafe() method (or whatever it ends up being called) should use the same implementation as described in RFC 4648. EDIT: I found another reference point in the Java 8 Base64 API... They also have a Base64 MIME encoding method which we may also want to implement. |
I don't know why '+' and '$' were chosen when this feature was implemented, but both characters need to be encoded for valid query strings. (
encodeURIComponent('+$') => '%2B%24'
)So I changed them to '_' and '.' ... and also removed the +/whitespace replacement as it's not needed anymore.