From 85a89846bbb2abeb5811f82bc2d5daebbe6a6c4d Mon Sep 17 00:00:00 2001 From: makeworld Date: Fri, 19 Jun 2020 13:33:53 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Making=20charset=20handlin?= =?UTF-8?q?g=20nicer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renderer/renderer.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/renderer/renderer.go b/renderer/renderer.go index a356ac8..cddb682 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -19,6 +19,9 @@ import ( "gitlab.com/tslocum/cview" ) +// Charset values that are compatible with UTF-8, lowercased. +var utfCharsets = []string{"", "utf-8", "us-ascii"} + // CanDisplay returns true if the response is supported by Amfora // for displaying on the screen. // It also doubles as a function to detect whether something can be stored in a Page struct. @@ -31,15 +34,16 @@ func CanDisplay(res *gemini.Response) bool { if err != nil { return false } - if strings.ToLower(params["charset"]) != "utf-8" && strings.ToLower(params["charset"]) != "us-ascii" && params["charset"] != "" { - // Amfora doesn't support other charsets - return false - } if mediatype != "text/gemini" && mediatype != "text/plain" { // Amfora doesn't support other filetypes return false } - return true + for _, charset := range utfCharsets { + if strings.ToLower(params["charset"]) == charset { + return true // Supported + } + } + return false } // convertRegularGemini converts non-preformatted blocks of text/gemini