fix: handle GB2312/GBK encoded files correctly - #18
Open
ChenyuHeee wants to merge 1 commit into
Open
Conversation
ChenyuHeee
force-pushed
the
fix/issue-6-gb2312-encoding
branch
from
August 6, 2026 08:28
6e5899a to
c80809a
Compare
- Add decodeTextFileContent() with UTF-8 strict decode + GBK fallback - Fix forceUpdateContent() and trackContent() encoding handling - Add 6 encoding tests (UTF-8, GBK, ASCII, empty, mixed content)
ChenyuHeee
force-pushed
the
fix/issue-6-gb2312-encoding
branch
from
August 6, 2026 08:31
c80809a to
28c15dc
Compare
Owner
|
感谢 PR~ 我在想有没有一种更好的方式支持所有编码,而不仅限于 UTF-8 和 GBK? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复内容
修复 #6 — GB2312/GBK 编码的中文文件在协同编辑时出现乱码。
new TextDecoder()默认 UTF-8,当 host 的源文件是 GB2312 编码时,guest 看到的中文变成乱码。修复:
common.ts新增decodeTextFileContent():TextDecoder('utf-8', { fatal: true })严格解码TextDecoder('gbk')修改了
forceUpdateContent()和trackContent()两处调用。测试
新增
src/fs/common.test.ts(6 个测试:UTF-8、GBK、ASCII、空内容、纯中文 GBK、混合内容)Closes #6