Repository navigation
fix: decode UTF-8 text previews as UTF-8 - #1566
Merged
CyanVoxel merged 1 commit intoNov 13, 2026
Merged
Conversation
chardet gives UTF-8 a low confidence when a file has only a few multi-byte characters, so a short file with emoji was detected as Windows-1254 and its preview showed mojibake. Use UTF-8 whenever the bytes decode as UTF-8, and fall back to chardet otherwise.
Collaborator
|
Checked and this fixes my issue, the emojis are now encoded correctly (though they aren't able to be rendered, but that's a different issue). |
CyanVoxel
approved these changes
Nov 13, 2026
CyanVoxel
left a comment
Member
There was a problem hiding this comment.
Thank you so much for the fix!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1564.
Text previews and thumbnails get their encoding from
detect_char_encoding, which uses chardet. chardet gives UTF-8 a low confidence when a file has only a few multi-byte characters, so a short UTF-8 file with emoji comes back as Windows-1254 (Turkish) at 0.3-0.5 confidence, and each emoji is decoded as several Latin characters:detect_char_encodingnow returnsutf-8whenever the file's bytes decode as UTF-8, and only asks chardet otherwise. Random bytes in a legacy single-byte encoding almost never form valid UTF-8, so files in Latin-1, Windows-125x and similar encodings still go to chardet as before. An empty file now returnsutf-8instead ofNone, which is what the text renderer already fell back to.Tasks Completed
tests/core/test_encoding.pycovers UTF-8 text with emoji (detected asutf-8and round-trips) and a Latin-1 file (still detected by chardet and decodes correctly). I ran the detector against these cases with chardet 5.2;ruff format --checkandruff checkpass on both files.