1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-19 19:25:24 +00:00

🐛 Handle empty META - fixes #176

This commit is contained in:
makeworld 2021-02-04 18:06:56 -05:00
parent abacacf5f5
commit 86bde5ec11
3 changed files with 18 additions and 5 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix downloading of pages that are too large or timed out
- `about:` URLs can be typed into the bottom bar (#167)
- Bookmarks modal closes on ESC like the others (#173)
- Handle empty META string (#176)
## [1.7.2] - 2020-12-21

View File

@ -136,7 +136,8 @@ func handleFavicon(t *tab, host, old string) {
cache.AddFavicon(host, cache.KnownNoFavicon)
return
}
if !strings.HasPrefix(res.Meta, "text/") {
if !strings.HasPrefix(res.Meta, "text/") && res.Meta != "" {
// Not a textual page
cache.AddFavicon(host, cache.KnownNoFavicon)
return
}

View File

@ -24,14 +24,25 @@ var ErrBadMediatype = errors.New("displayable mediatype is not handled in the co
// isUTF8 returns true for charsets that are compatible with UTF-8 and don't need to be decoded.
func isUTF8(charset string) bool {
utfCharsets := []string{"", "utf-8", "us-ascii"}
for i := range utfCharsets {
if strings.ToLower(charset) == utfCharsets[i] {
for _, s := range utfCharsets {
if charset == s || strings.ToLower(charset) == s {
return true
}
}
return false
}
// getMetaInfo returns the output of mime.ParseMediaType, but handles the empty
// META which is equal to "text/gemini; charset=utf-8" according to the spec.
func decodeMeta(meta string) (string, map[string]string, error) {
if meta == "" {
params := make(map[string]string)
params["charset"] = "utf-8"
return "text/gemini", params, nil
}
return mime.ParseMediaType(meta)
}
// 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.
@ -40,7 +51,7 @@ func CanDisplay(res *gemini.Response) bool {
// No content
return false
}
mediatype, params, err := mime.ParseMediaType(res.Meta)
mediatype, params, err := decodeMeta(res.Meta)
if err != nil {
return false
}
@ -82,7 +93,7 @@ func MakePage(url string, res *gemini.Response, width, leftMargin int, proxied b
}
// Otherwise, the error is EOF, which is what we want.
mediatype, params, _ := mime.ParseMediaType(res.Meta)
mediatype, params, _ := decodeMeta(res.Meta)
// Convert content first
var utfText string