varkor / quiver

A modern commutative diagram editor for the web.
https://q.uiver.app
MIT License
2.43k stars 83 forks source link

`unescape`-`encodeURIComponent` trick #167

Closed kokic closed 1 year ago

kokic commented 1 year ago

I noticed in the source code that the base64 encoding for QuiverImportExport.base64.export uses unescape, but as pointed out here unescape() - JavaScript | MDN, unescape is non-standard and no longer recommended (deprecated).

At the same time, the unescape - encodeURIComponent trick can be replaced by String.fromCharCode(...encoder.encode(_)), where the encoder is a TextEncoder object.

e.g.

const encoder = new TextEncoder(); // globally

btoa(String.fromCharCode(...encoder.encode(JSON.stringify(output))))
// btoa(unescape(encodeURIComponent(JSON.stringify(output))))

This is a somewhat offensive suggestion, please forgive me. If you choose to keep using unescape for any other purpose, please ignore and close this issue.

varkor commented 1 year ago

I remember when I first wrote that function, I realised unescape was deprecated, but the alternatives I found had issues with some characters (I don't remember which character class now, maybe emoji). I don't remember whether I tried TextEncoder, though. I'll try it out, and if it works, I'll replace the current implementation. Thanks for the suggestion :)

varkor commented 1 year ago

This has been fixed in https://github.com/varkor/quiver/commit/2895900bfab72f08bdacce457f305571c75595de.