Skip to content

Conversation

@majiayu000
Copy link

Fixes #513

Changes

  • Add ToUTF8String() utility function to detect and convert UTF-16 LE/BE with BOM to UTF-8
  • Apply encoding conversion in CLI mode, TUI file view, and stash loading
  • Add comprehensive tests for encoding conversion

UTF-16 encoded files were not being rendered correctly because the raw
bytes were directly converted to strings without encoding detection.

This adds a ToUTF8String utility function that:
- Detects UTF-16 LE BOM (0xFF 0xFE) and converts to UTF-8
- Detects UTF-16 BE BOM (0xFE 0xFF) and converts to UTF-8
- Strips UTF-8 BOM (0xEF 0xBB 0xBF) if present
- Falls back to treating content as UTF-8 if no BOM detected

The function is now used in all file reading paths:
- CLI mode (main.go)
- TUI document view (ui/ui.go)
- TUI stash/file browser (ui/stash.go)

Fixes charmbracelet#513

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Signed-off-by: majiayu000 <[email protected]>
@majiayu000 majiayu000 requested a review from a team as a code owner December 30, 2025 18:23
@majiayu000 majiayu000 requested review from andreynering and raphamorim and removed request for a team December 30, 2025 18:23
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.

Problems parsing UTF16 files

1 participant