Skip to content

Decode and preserve BOM-marked UTF-16 text files #230

Description

@bholmesdev

What happened?

Hubble renders BOM-marked UTF-16 text files as mojibake instead of decoding them. This was reported during WinGet verification with ChangedFiles.txt and is reproducible on current main (0.1.25).

The editor currently reads every editable text file with fs.readFile(resolved, "utf8"). A UTF-16 file therefore appears as text such as ��\0C\0h\0a\0n\0g\0e\0d....

How can we reproduce it?

  1. Create ChangedFiles.txt encoded as UTF-16LE or UTF-16BE with a BOM. Windows PowerShell 5.1 redirection commonly produces UTF-16LE files.
  2. Open its parent folder in Hubble Desktop.
  3. Open ChangedFiles.txt.
  4. Observe replacement characters and NUL-separated letters instead of the file contents.

What did you expect to happen?

Hubble should detect a UTF-16 BOM, decode the file correctly, and preserve its encoding when saving edits.

What actually happened?

The file is decoded as UTF-8 and displayed as mojibake. Editing and saving is higher risk: the preload encodes the corrupted editor string as UTF-8, which can irreversibly rewrite the original file.

Screenshots, videos, logs, or notes

Original WinGet verification report and screenshot: microsoft/winget-pkgs#408140 (comment)

Current implementation areas:

  • apps/desktop/electron/main.ts: desktop:read-file-text assumes UTF-8
  • apps/desktop/electron/main.ts: content search also assumes UTF-8
  • apps/desktop/electron/preload.ts: saves encode editor strings as UTF-8

No duplicate issue found.

App version

Reproduced on current main (0.1.25); originally reported against 0.1.21 on Windows.

Does this block your work?

Partially — I have a workaround

Acceptance criteria

  • BOM-marked UTF-16LE and UTF-16BE .txt and Markdown files display correctly.
  • Saving an existing UTF-16 file preserves its original encoding and BOM.
  • UTF-8 reads and saves remain unchanged.
  • Content search decodes supported text encodings consistently with the editor.
  • Regression tests cover UTF-16LE/BE decode and edit/save round trips.

Blocked by

None - can start immediately

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-discussionOpen product or technical questions; discuss on the issue before implementing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions