Skip to content

fix: encoding utf8 strings in node 20#409

Merged
tschaub merged 1 commit intotschaub:mainfrom
everett1992:encoding
Jan 31, 2025
Merged

fix: encoding utf8 strings in node 20#409
tschaub merged 1 commit intotschaub:mainfrom
everett1992:encoding

Conversation

@everett1992
Copy link
Copy Markdown

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
Copy Markdown
Author

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.
@tschaub tschaub merged commit 2de9b90 into tschaub:main Jan 31, 2025
@tschaub
Copy link
Copy Markdown
Owner

tschaub commented Jan 31, 2025

Thanks for the fix, @everett1992!

@everett1992
Copy link
Copy Markdown
Author

Thanks, when will this be published?

@tschaub
Copy link
Copy Markdown
Owner

tschaub commented Feb 6, 2025

Fix is included in the v5.5.0 release.

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