From 1470b42ce6fb909e9f5c1ea6b13b550bc9367fe3 Mon Sep 17 00:00:00 2001 From: srinithivijayakumars139-wq Date: Sun, 22 Feb 2026 14:39:40 +0530 Subject: [PATCH] Fix binary file rendering bug in rich-cli --- empty.txt | 0 src/rich_cli/__main__.py | 8 +++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 empty.txt diff --git a/empty.txt b/empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/rich_cli/__main__.py b/src/rich_cli/__main__.py index 98df6bb..ac95ae1 100644 --- a/src/rich_cli/__main__.py +++ b/src/rich_cli/__main__.py @@ -102,7 +102,13 @@ def read_resource(path: str, lexer: Optional[str]) -> Tuple[str, Optional[str]]: if path == "-": return (sys.stdin.read(), None) - with open(path, "rt", encoding="utf8", errors="replace") as resource_file: + with open(path,"rb") as check_file: + chunk = check_file.read(1024) + if b"\x00" in chunk: + on_error("cannot render binary file") + return + + with open(path, "rt", encoding="utf8") as resource_file: text = resource_file.read() if not lexer: _, dot, ext = path.rpartition(".")