Skip to content

fix: handle GB2312/GBK encoded files correctly - #18

Open
ChenyuHeee wants to merge 1 commit into
kermanx:mainfrom
ChenyuHeee:fix/issue-6-gb2312-encoding
Open

fix: handle GB2312/GBK encoded files correctly#18
ChenyuHeee wants to merge 1 commit into
kermanx:mainfrom
ChenyuHeee:fix/issue-6-gb2312-encoding

Conversation

@ChenyuHeee

@ChenyuHeee ChenyuHeee commented Aug 6, 2026

Copy link
Copy Markdown

修复内容

修复 #6 — GB2312/GBK 编码的中文文件在协同编辑时出现乱码。

new TextDecoder() 默认 UTF-8,当 host 的源文件是 GB2312 编码时,guest 看到的中文变成乱码。

修复common.ts 新增 decodeTextFileContent()

  1. TextDecoder('utf-8', { fatal: true }) 严格解码
  2. 失败则 fallback 到 TextDecoder('gbk')

修改了 forceUpdateContent()trackContent() 两处调用。

测试

新增 src/fs/common.test.ts(6 个测试:UTF-8、GBK、ASCII、空内容、纯中文 GBK、混合内容)

Closes #6

@ChenyuHeee
ChenyuHeee force-pushed the fix/issue-6-gb2312-encoding branch from 6e5899a to c80809a Compare August 6, 2026 08:28
- 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
ChenyuHeee force-pushed the fix/issue-6-gb2312-encoding branch from c80809a to 28c15dc Compare August 6, 2026 08:31
@kermanx

kermanx commented Aug 26, 2026

Copy link
Copy Markdown
Owner

感谢 PR~ 我在想有没有一种更好的方式支持所有编码,而不仅限于 UTF-8 和 GBK?

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.

p2p gb2312 中文乱码

2 participants