-
Notifications
You must be signed in to change notification settings - Fork 56
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
Method for URL-safe project serialization #102
Comments
how come btoa throws on non-latin characters? isn't it supposed to handle general bytes? therefore encoding anything, whatever the encoding? |
|
https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem |
Thanks for the details! I feel there should be a warning somewhere in the API since this is so common in browser code! I'd have expected any string given to btoa to be converted to a Uint8Array before being converted to base64 to avoid any encoding issue... |
BTW I see many "solutions" on the web mentioning the use of a TextEncoder to convert everything to UTF-8 before doing the base64 conversion, why isn't the version chosen for https://github.com/lit/lit.dev/blob/fd4c34e71b47267f3672a2debe52807042f22cc2/packages/lit-dev-content/src/pages/playground.ts#L31 ? |
I don't know, we should probably use it! I thought maybe TextEncoder wasn't available in all browsers at the time it was written, but that doesn't seem to be true. 🤷 |
It's not as easy as you'd think to serialize the state of a project for e.g. sticking in a URL, because
btoa
throws on non-Latin-1 characters, so special handling there is required. Also, base64url is a better scheme (-
and_
instead of+
and/
), because it's less likely to get mis-encoded somehow (especially the+
which will become a space).Let's add something like
serialize()
anddeserialize()
toproject
andide
, to make this use case simpler.The text was updated successfully, but these errors were encountered: