Skip to content

fix: read text whose preview is cut inside a character - #23

Merged
heoblitz merged 3 commits into
toss:mainfrom
wjdtjq6:fix/text-preview-multibyte
Oct 15, 2026
Merged

heoblitz merged 3 commits into
toss:mainfrom
wjdtjq6:fix/text-preview-multibyte

Conversation

@wjdtjq6

@wjdtjq6 wjdtjq6 commented Oct 13, 2026

Copy link
Copy Markdown

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:

  • a 60 kB Korean log file (한 is three bytes; 32768 % 3 == 2) shows as binary in the Files panel, with no preview;
  • a large JSON response with non-ASCII text past the cap loses its body text in the Network panel.

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 that 0xFF, a stray continuation byte, and a whole body ending inside a character still read as binary. The text tests fail on main (kind == "binary", text == nil).

소정섭 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
heoblitz merged commit dd79a6a into toss:main Oct 15, 2026
5 checks passed
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.

2 participants