From ca23e43e0e95014ddd5f8d5e02e1118f5e2978f5 Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Wed, 12 Aug 2026 01:38:24 -0400 Subject: Handle blobs GitHub cannot preview Binary files with no preview (a .ttf, say) have no rawLines, no colorizedLines and no richText, so the blob view's final branch threw on a null textLines and the page 500ed. Offer the raw file instead. Co-Authored-By: Claude Opus 5 --- src/app.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/app.test.ts') diff --git a/src/app.test.ts b/src/app.test.ts index 59ed352..94bf205 100644 --- a/src/app.test.ts +++ b/src/app.test.ts @@ -92,6 +92,28 @@ describe("sidebar fragment", () => { }); }); +describe("blob view", () => { + const blob = { + repo: { owner: "justrajdeep", name: "fonts" }, + branch: "master", + path: "Times New Roman.ttf", + language: null, + size: "815 KB", + image: false, + textLines: null, + htmlLines: null, + htmlContent: null, + }; + + // GitHub previews neither the text nor the bytes of most binary files. + it("should offer the raw file when there is nothing to display", () => { + const html = eta.render("blob.eta", blob); + + assert.match(html, /This file cannot be displayed\./); + assert.match(html, /href="\/justrajdeep\/fonts\/raw\/master\/Times New Roman.ttf">View raw/); + }); +}); + describe("redirects to GitHub", () => { // An HTTP redirect would be caught by the extension's declarativeNetRequest // rules and bounced straight back here. -- cgit v1.3.1