Siorki / RegPack

Self-contained packer for size-constrained JS code
Other
301 stars 14 forks source link

regPack.html - Base64 output fails for chars outside of the Latin1 range #52

Closed magnitudoOrg closed 8 years ago

magnitudoOrg commented 8 years ago

btoa() throws an InvalidCharacterError for Unicode chars like 🔥 ("\uD83D\uDD25"): "Uncaught InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."

I created a pull request as suggestion to solve this by btoa(unescape(encodeURIComponent(outputCode[index]))

Quick test by inverted function: b64 = btoa(unescape(encodeURIComponent(outputCode[1]))); decodeURIComponent(escape(atob(b64))) == outputCode[1]; // must be the same as original text

Also see http://stackoverflow.com/questions/23223718/failed-to-execute-btoa-on-window-the-string-to-be-encoded-contains-characte

Siorki commented 8 years ago

Added Unicode-safe atob() and btoa() implementations from MDN to class StringHelper.