From 87d067c552e85e1067ae83cfbdaa03130bea2884 Mon Sep 17 00:00:00 2001 From: valoq Date: Fri, 15 May 2026 05:59:54 +0200 Subject: [PATCH] fix!: enhance detection for binary previews (#2561) * improve text detection * update doc --- doc.md | 2 +- misc.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc.md b/doc.md index b2ef5ae8..43e68c64 100644 --- a/doc.md +++ b/doc.md @@ -1077,7 +1077,7 @@ Note that preserving other attributes like ownership of change/birth timestamp i Show previews of files and directories at the rightmost pane. If the file has more lines than the preview pane, the rest of the lines are not read. -Files containing the null character (U+0000) in the read portion are considered binary files and displayed as `binary`. +Files are considered binary and displayed as `binary` if the read portion contains a control character other than tab, newline, vertical tab, form feed, carriage return, backspace, or escape. ## previewer (string) (default ``) (not filtered if empty) diff --git a/misc.go b/misc.go index 8c069a58..3df73529 100644 --- a/misc.go +++ b/misc.go @@ -500,9 +500,11 @@ func readLines(reader io.ByteReader, maxLines int) (lines []string, binary bool, switch currState { case stateNormal: - switch b { - case 0: + // C0 controls outside \b \t \n \v \f \r \033 and DEL indicate binary content. + if b < 0x07 || (b > 0x0D && b < 0x1B) || (b > 0x1B && b < 0x20) || b == 0x7F { return nil, true, false + } + switch b { case '\033': currState = stateEsc case '\r':