Repository navigation
fix: read text whose preview is cut inside a character - #23
Merged
Merged
Conversation
added 2 commits
October 13, 2026 22:28
Files previews the first 32 kB of a file and Network keeps the first 512 kB of a body. Both cuts count bytes, so one can land inside a character of two to four bytes, and the bytes left over made the whole head fail to decode: a long Korean log showed as binary, and a large JSON response lost its text. The incomplete character at the cut is now dropped. Anything else that is not UTF-8 still reads as binary, and a file read whole is decoded strictly as before.
A body kept whole that still ends inside a character is not text, as Files already treats a file read whole.
heoblitz
approved these changes
Oct 15, 2026
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
Files previews the first 32 kB of a file, and Network keeps the first 512 kB of a body. Both cuts count bytes, so one can land inside a character of two to four bytes, and the leftover bytes made the whole head fail to decode as UTF-8:
한is three bytes; 32768 % 3 == 2) shows as binary in the Files panel, with no preview;String(utf8Head:)drops an incomplete trailing character at the cut and nothing else: a byte that cannot start a character still reads as binary. Files applies it only to a head that was truncated, so a file read whole that ends inside a character is still not opened for editing as text; Network applies it only to a body that was cut.Changelog
Fix text files and response bodies with non-ASCII text showing as binary when the preview cut lands inside a character.
Test Plan
swift test: 166 tests in 12 suites passed. New tests move the cut through every byte offset ofé,한and🙂for both Files (previewsTextCutInsideACharacter) and Network bodies (keepsTextCutInsideACharacter), and check that0xFF, a stray continuation byte, and a whole body ending inside a character still read as binary. The text tests fail onmain(kind == "binary",text == nil).