Skip to content
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

fix: ut8-string encode/decode #76

Merged
merged 3 commits into from
Nov 23, 2023
Merged

fix: ut8-string encode/decode #76

merged 3 commits into from
Nov 23, 2023

Conversation

gagdiez
Copy link
Contributor

@gagdiez gagdiez commented Nov 21, 2023

There was a bug by which we were storing the strings as unicode bytes instead of utf8 bytes. This was a bug since the specification clearly says that the encoding must be utf8.

This commit fixes such bug using the TextEncode / TextDecode tools, which are widely supported by modern browsers and node versions.

There was a bug by which we were storing the strings as unicode
bytes instead of utf8 bytes. This was a bug since the specification
clearly says that the encoding must be utf8.

This commit fixes such bug using the TextEncode / TextDecode tools,
which are widely supported by modern browsers and node versions.
@gagdiez
Copy link
Contributor Author

gagdiez commented Nov 21, 2023

Using TextEncode and TextDecode will not work with borsh-js... will keep checking alternatives

@gagdiez gagdiez marked this pull request as ready for review November 22, 2023 10:41
@gagdiez
Copy link
Contributor Author

gagdiez commented Nov 22, 2023

Ended up using some library as guide [1] to manually create the encoder. To make sure it works correctly, I added tests encoding/decoding characters from a wide range of the utf8 spectrum [2], and used online tools [3] to check my results against.

[1] https://github.com/mathiasbynens/utf8.js/blob/master/utf8.js
[2] https://www.fileformat.info/info/charset/UTF-8/list.htm
[3] https://mothereff.in/utf-8 + https://cryptii.com/pipes/integer-encoder

@ailisp
Copy link
Member

ailisp commented Nov 23, 2023

Thank you! This is a very important fix.

Using TextEncode and TextDecode will not work with borsh-js... will keep checking alternatives

Do you mean they do not work in near-sdk-js? If so, we have some custom method for utf8 encode or decode, we can add on sdk-js side to support TextEncoder/TextDecoder (not full TextEncoder/TextDecoder class as browser does, but would be sufficient for this PR), but before that your solution is the best possible one.

@ailisp ailisp merged commit abe2701 into master Nov 23, 2023
5 checks passed
@gagdiez gagdiez deleted the fix-utf8 branch November 23, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants