Repository navigation
Conversation
"Open text file" decides by extension and size alone, so a binary whose name gives nothing away opens straight into the editor, where saving it back can damage the file. Read the first chunk of whatever the editor is asked to show, and when it looks binary (a NUL byte or undecodable UTF-8, the heuristic git uses) warn before opening, with Download offered right there. Every route into the editor goes through this, so a double-click with "Prefer editor" set warns as well: the listing decides what is offered, the bytes decide what is safe to display.
This branch has not been deployed
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.
Builds upon #1524 — the content check promised in
#901 (comment). Draft until that one lands;
the file list here also shows its changes, this PR is the single commit on top.
"Open text file" decides by extension and size alone, so a binary whose name gives nothing away opens straight
into the editor, where saving it back can damage the file. This weighs the bytes instead: before the editor opens
anything, its first 8 KiB is read through
fsread1and classified in plain JS by the rule git uses for buffers (aNUL byte or undecodable UTF-8 = binary — a multi-byte character split by the cut does not count as undecodable). A
file that looks binary gets a warning first — "This doesn't appear to be a text file", with Open anyway,
Download and Cancel.
The check sits in
edit_file(), the single choke point, so it applies to every route in: the context menu warns,and a double-click with "Prefer editor" warns too rather than opening a binary silently. Nothing reads the content
twice and no route skips it; the listing-based check still decides what is offered (
editor_supports()isuntouched), the bytes decide what is safe to show. Cost is one small read per editor open; unreadable files count
as text and let the editor report the error itself.
Tests: new
TestFiles.testEditorNonTextWarningcovers Cancel, Open anyway, and Download, plus that a text fileopens with no dialog; #1524's
testDefaultFileActionnow expects the warning on its binary fixtures. 3/3 pass onfedora-44 / chromium in the nested-VM harness.
I wrote this with an AI coding assistant (opencode + Qwen); I reviewed, tested, and carry every line myself.
Files: Warns before editing non-text files
Opening a file that turns out to be binary now says so: the editor checks the first chunk of bytes and offers
"Open anyway", "Download" or Cancel instead of showing garbled content that could be saved back over.