StableLib / stablelib

A stable library of useful TypeScript/JavaScript code
https://www.stablelib.com
Other
173 stars 35 forks source link

[utf8] some emojis trigger invalid UTF8 string #66

Closed atomrc closed 9 months ago

atomrc commented 9 months ago

When trying to encode strings containing emojis, some emojis seem to trigger errors.

a simple reproducer would be the following:

utf8.encode('❤️') // Uncaught Error: utf8: invalid string

Any idea if there is a workaround I could use? Could this be fixed at the library level?

Thanks :)

atomrc commented 9 months ago

As a side note, this works. So I do believe @stablelib/utf-8 encode function should be able to handle that payload :)

    const enc = new TextEncoder().encode('❤️');
    const dec = decode(enc);
dchest commented 9 months ago

Thank you! Fixed in 1.0.2.

atomrc commented 9 months ago

Thank you @dchest for such a fast fix 🙏