Don't assume character encoding when loading in fallback mode
This commit is contained in:
parent
5d2fb53510
commit
de68ecbe4b
|
@ -258,8 +258,7 @@ class BrowserWebViewController: UIViewController {
|
|||
|
||||
self.loadedFallback = true
|
||||
|
||||
// todo: probably shouldn't assume this is UTF-8
|
||||
self.webView.load(body, mimeType: mimeType, characterEncodingName: "utf-8", baseURL: self.url)
|
||||
self.webView.load(body, mimeType: mimeType, characterEncodingName: response.encodingName ?? "utf-8", baseURL: self.url)
|
||||
// When showing an image, the safe area insets seem to be ignored. This isn't perfect
|
||||
// (there's a little extra space between the bottom of the nav bar and the top of the image),
|
||||
// but it's better than the image being obscured.
|
||||
|
|
|
@ -38,10 +38,17 @@ public struct GeminiResponse {
|
|||
return UTType.types(tag: mimeType, tagClass: .mimeType, conformingTo: nil).first
|
||||
}
|
||||
|
||||
public var encodingName: String? {
|
||||
guard let parameters = mimeTypeParameters else {
|
||||
return nil
|
||||
}
|
||||
return parameters["charset"]
|
||||
}
|
||||
|
||||
public var bodyText: String? {
|
||||
guard let body = body, let parameters = mimeTypeParameters else { return nil }
|
||||
guard let body = body else { return nil }
|
||||
let encoding: String.Encoding
|
||||
switch parameters["charset"]?.lowercased() {
|
||||
switch encodingName?.lowercased() {
|
||||
case nil, "utf-8":
|
||||
// The Gemini spec defines UTF-8 to be the default charset.
|
||||
encoding = .utf8
|
||||
|
|
Loading…
Reference in New Issue