fix(web): large GBK text previews keep their Chinese characters #48133
main fromrefs/pull/48133/head·opened View on GitHubIn a GBK text file larger than 1 MB, Chinese characters past the first megabyte showed as replacement symbols. The full-file download always decoded as UTF-8, while the 1 MB preview read falls back to GB18030. The download now reads strictly as UTF-8. At the first byte that is not UTF-8, it rereads the exact bytes it has received so far as GB18030 (keeping any leading byte-order-mark bytes and any character split across chunks) and continues in that encoding. If the bytes are not valid GB18030 either, it falls back to UTF-8 with replacement characters, as before.
Related: #45854
Reproduction on main#
Commit cc19795ea7 (main). The Chinese characters are displayed as replacement symbols. The rest of the line is readable. Expected: The preview shows the Chinese characters from the file, as it does in a small GBK preview.
- Open a GBK text file larger than 1 MB whose first megabyte is ASCII and whose later lines contain Chinese characters.
- Scroll to the later lines after the download finishes.
The cause is at apps/web/src/components/files/fullFileText.ts:45. Ran pnpm scenarios:prove scripts/scenarios/large-gbk-workspace-text-keeps-its-characters.e2e.ts --target web with the repro scenario added: it failed in 2 of 2 runs on a clean boat.dev VM, with expected "Final status: ����" to be "Final status: 中文" in the output.
Evidence#
Environment: The web app in Chromium on Linux x64, a fresh checkout on a boat.dev VM reset before each run.
Proven: the repro fails at the test commit e9377c1b9b and passes on the head 171b14071c, both on main 3eb5894919.
| Before | After | |
|---|---|---|
| Commit | e9377c1b9b | 171b14071c |
| Result | ASSERTION_FAILED: expected "Final status: ����" to be "Final status: 中文" | passed |
| last line of the large text preview | ![]() The Chinese characters are displayed as replacement symbols. The rest of the line is readable. | ![]() The preview shows the Chinese characters from the file, as it does in a small GBK preview. |
| failure | ![]() | |
| Recording | Before: recording | After: recording |
Tests#
- e9377c1b9b adds the failing test, alone, before the fix.
pnpm exec vp run check:changed 3eb58949194ce010be0af51d861d3292127e8a37passed on head.
Not in this change#
- The mobile full-file download (apps/mobile/src/features/files/useFullFileText.ts) decodes with response.text, which is UTF-8 only, so it likely has the same problem. It is left for a mobile-specific change.
- A large file whose bytes are not GB18030 either keeps a second UTF-8 copy of its text while downloading, so it uses up to twice the memory during the download.
Who did the work#
- Repro written by GPT 6.2 Sol, in Codex
- Written by Claude Opus 5.5, in Claude Code
- Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex
- Reproduction, checks and proof run by a program on base and head, not by an agent
Made in T3 Code by GPT 6.2 Sol and Claude Opus 5.5
- 1
- 2
Pushedc57f9e5
Pushedb6bef37
The automated pipeline stopped on this pull request and will not merge it:
the proof could not be captured: the agent's turn was cut short: failed
It stays open for a person to finish or close.
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
StiensWout(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.





macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes