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: encoding utf8 strings in node 20 #409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

everett1992
Copy link

The writeFileUtf8 binding used by node 20 was not correctly encoding strings as utf8, and recording the file length as
String.prototype.length, which returns number of utf-16 code units.

If you wrote a string containing code points with a different number of utf-8 code units than utf-16 code units, then read the file back the returned string would be truncated by the difference in the number of code units.

@everett1992
Copy link
Author

Looks like this partially overlaps with https://github.com/tschaub/mock-fs/pull/311/files

The writeFileUtf8 binding used by node 20 was not correctly encoding
strings as utf8, and recording the file length as
String.prototype.length, which returns number of utf-16 code units.

If you wrote a string containing code points with a different number of
utf-8 code units than utf-16 code units, then read the file back the
returned string would be truncated by the difference in the number of
code units.
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.

1 participant