Add setting for default charset

This commit is contained in:
Fierelier 2021-03-25 20:58:22 +01:00
parent 14c33d6ec8
commit c4d2463372
2 changed files with 5 additions and 3 deletions

View File

@ -5,6 +5,8 @@ home = https://example.com
useragent = BirdyNet/$VER ($OS) useragent = BirdyNet/$VER ($OS)
# Which protocol to use when none is given in the address bar # Which protocol to use when none is given in the address bar
defaultProtocol = https defaultProtocol = https
# Which charset to use when none is given in the header. https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1 defines that iso-8859-1 should be used. You may also use utf-8 though, if it's better for the pages you visit.
defaultCharset = iso-8859-1
[accessibility] [accessibility]
# Which background color (CSS color) should be chosen for websites? "default" for system's default. "white" is recommended for compatibility. # Which background color (CSS color) should be chosen for websites? "default" for system's default. "white" is recommended for compatibility.

View File

@ -188,14 +188,14 @@ class browserWindow(QMainWindow):
htm = response["body"] htm = response["body"]
contentType, contentTypeArguments = getContentType(response["headers"],"text") contentType, contentTypeArguments = getContentType(response["headers"],"text")
if not "charset" in contentTypeArguments: contentTypeArguments["charset"] = "utf-8" if not "charset" in contentTypeArguments: contentTypeArguments["charset"] = config["default"]["defaultCharset"]
print("content-type: " +contentType+ "\n" +prettyJson(contentTypeArguments)) print("content-type: " +contentType+ "\n" +prettyJson(contentTypeArguments))
try: try:
htm = htm.decode(contentTypeArguments["charset"],errors="ignore") htm = htm.decode(contentTypeArguments["charset"],errors="ignore")
except Exception as e: except Exception as e:
print("decoding html as '" +contentTypeArguments["charset"]+ "' failed, trying utf-8...") print("decoding html as '" +contentTypeArguments["charset"]+ "' failed, trying " +config["default"]["defaultCharset"]+ "...")
htm = htm.decode("utf-8",errors="ignore") htm = htm.decode(config["default"]["defaultCharset"],errors="ignore")
self.cDoc.cRenderHtml(htm,contentType) self.cDoc.cRenderHtml(htm,contentType)
end = time.time() end = time.time()