Display page even if mediatype params are malformed

Fixes #141
This commit is contained in:
makeworld 2021-02-17 14:58:55 -05:00
parent c9468c11ef
commit a7f4ab35cb
2 changed files with 13 additions and 6 deletions

View File

@ -10,11 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ability to set custom keybindings in config (#135) - Ability to set custom keybindings in config (#135)
- Added scrollbar, by default only appears on pages that go off-screen (#89, #107) - Added scrollbar, by default only appears on pages that go off-screen (#89, #107)
- More internal about pages, see `about:about` (#160, 187) - More internal about pages, see `about:about` (#160, 187)
- Sensitive input fields (status code 11) display with asterisks over the text (#106)
### Changed ### Changed
- Update cview to `d776e728ef6d2a9990a5cd86a70b31f0678613e2` for large performance and feature updates (#107) - Update cview to `d776e728ef6d2a9990a5cd86a70b31f0678613e2` for large performance and feature updates (#107)
- Update to tcell v2 (dependency of cview) - Update to tcell v2 (dependency of cview)
- Display page even if mediatype params are malformed (#141)
- Sensitive input fields (status code 11) display with asterisks over the text (#106)
### Fixed ### Fixed
- Don't use cache when URL is typed in bottom bar (#159) - Don't use cache when URL is typed in bottom bar (#159)

View File

@ -32,15 +32,21 @@ func isUTF8(charset string) bool {
return false return false
} }
// getMetaInfo returns the output of mime.ParseMediaType, but handles the empty // decodeMeta returns the output of mime.ParseMediaType, but handles the empty
// META which is equal to "text/gemini; charset=utf-8" according to the spec. // META which is equal to "text/gemini; charset=utf-8" according to the spec.
func decodeMeta(meta string) (string, map[string]string, error) { func decodeMeta(meta string) (string, map[string]string, error) {
if meta == "" { if meta == "" {
params := make(map[string]string) return "text/gemini", make(map[string]string), nil
params["charset"] = "utf-8"
return "text/gemini", params, nil
} }
return mime.ParseMediaType(meta)
mediatype, params, err := mime.ParseMediaType(meta)
if mediatype != "" && err != nil {
// The mediatype was successfully decoded but there's some error with the params
// Ignore the params
return mediatype, make(map[string]string), nil
}
return mediatype, params, err
} }
// CanDisplay returns true if the response is supported by Amfora // CanDisplay returns true if the response is supported by Amfora