Skip to content

fix(editor): open non-UTF-8 text files read-only in editors - #4022

Merged
JammingBen merged 2 commits into
mainfrom
fix/editor-non-utf8-read-only
Oct 27, 2026
Merged

JammingBen merged 2 commits into
mainfrom
fix/editor-non-utf8-read-only

Conversation

@JammingBen

@JammingBen JammingBen commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Description

Text editors (e.g. the text editor app) loaded file contents with responseType: 'text'. The browser then replaced every byte that isn't valid UTF-8 (e.g. umlauts in a Latin-1 file) with U+FFFD, and the next save wrote those replacement characters back. That silently destroyed the original characters.

Changes:

  • AppWrapper now loads text as raw bytes and decodes it with the new decodeTextContent helper. It detects UTF-16 by BOM and uses UTF-8 otherwise. If the bytes aren't valid UTF-8, it falls back to windows-1252 for display and reports the decoding as lossy.
  • A file that can't be decoded losslessly opens read-only. Editors show a warning suggesting »Save As...« for a UTF-8 copy.

In collaborative (Yjs) sessions, a non-UTF-8 file is kept out of the shared room: the session runs locally, like it does for vault files. Every client opens such a file read-only, so there is nobody to collaborate with, and it can't be loaded into the room twice. A file that becomes non-UTF-8 through an external write while open is handled like any other external update (rare edge case, not worth the effort).

@JammingBen JammingBen self-assigned this Oct 26, 2026
@JammingBen
JammingBen force-pushed the fix/editor-non-utf8-read-only branch from 70da816 to d540166 Compare October 26, 2026 12:06
@JammingBen
JammingBen marked this pull request as ready for review October 26, 2026 12:25
@JammingBen
JammingBen requested a review from kulmann October 26, 2026 12:25
@JammingBen
JammingBen merged commit 9f798c5 into main Oct 27, 2026
27 checks passed
@JammingBen
JammingBen deleted the fix/editor-non-utf8-read-only branch October 27, 2026 07:25
@openclouders openclouders mentioned this pull request Oct 27, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants