portable-secret icon indicating copy to clipboard operation
portable-secret copied to clipboard

[Bug] The generated secret.html file does not support UTF-8 chars

Open Unkn0wnCreator opened this issue 3 years ago • 1 comments

Hi,

When I use chars like the german-umlaute "öäü" they will get Replaced with ���

Maybe the secret.html is exported with ASCII encoding and not UTF-8 so that the chars are lost when JS is handling them?

Unkn0wnCreator avatar Dec 22 '22 00:12 Unkn0wnCreator

I'm not a web developer, this is one quirk of Javascript I have not had time to fight with and tame.

The btoa() method creates a Base64-encoded ASCII string from a binary string

Except if the string contains unicode, then btoa() chokes on it.

Probably related to that.

I'll eventually get around to look into it and fix it.

mprimi avatar Dec 22 '22 17:12 mprimi

Is this fixed?

gamedevsam avatar Jan 06 '23 22:01 gamedevsam

Is this fixed?

I did fork the project and fix it (see: https://github.com/TeddyBear06/portable-secret) but the maintainer won't merge as stated here (and we all understand why :innocent:): https://github.com/mprimi/portable-secret/discussions/29.

Working live version: https://lfconsult.fr/portable-secret/index.html

Generate Decrypt

Feel free to use my fork/fix.

TeddyBear06 avatar Jan 08 '23 10:01 TeddyBear06

@TeddyBear06 is the change to blob you proposed (https://github.com/mprimi/portable-secret/pull/23/files) sufficient to handle these non-ascii characters? Because if so I'm inclined to take your change.

mprimi avatar Jan 10 '23 15:01 mprimi

Hey @mprimi

Short answer: Yep.

Long answer: Blobs aren't "encoding aware" (it's just raw binary data after all). The Blob will store the supplied content "as is" and spit it out when we call window.URL.createObjectURL(blob) (what btoa() doesn't as it expects caracters that only occupy less than 1 byte, see: https://developer.mozilla.org/en-US/docs/Web/API/btoa#unicode_strings). As the target HTML file is correctly declared as an UTF-8 encoded document, UTF-8 caracters are handled as expected.

I hope I'm not missing something along the way but, that's the whole idea.

TeddyBear06 avatar Jan 10 '23 18:01 TeddyBear06