From 2d3b9e435bb3a8294316fe7b10907cb608f10241 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 6 Jan 2009 22:06:14 +0000 Subject: Charset fallbacks. If we don't support the charset declared in the HTTP header, fall back to autodetect. If we don't support the charset declared in a meta charset, fall back to Windows-1252. svn path=/trunk/netsurf/; revision=5974 --- render/html.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'render/html.c') diff --git a/render/html.c b/render/html.c index 047cd9114..70ee5ccb3 100644 --- a/render/html.c +++ b/render/html.c @@ -143,6 +143,16 @@ bool html_create(struct content *c, const char *params[]) /* Create the parser binding */ error = binding_create_tree(c, html->encoding, &html->parser_binding); + if (error == BINDING_BADENCODING && html->encoding != NULL) { + /* Ok, we don't support the declared encoding. Bailing out + * isn't exactly user-friendly, so fall back to autodetect */ + talloc_free(html->encoding); + html->encoding = NULL; + + error = binding_create_tree(c, html->encoding, + &html->parser_binding); + } + if (error != BINDING_OK) goto error; @@ -215,6 +225,23 @@ encoding_change: /* Create new binding, using the new encoding */ err = binding_create_tree(c, c->data.html.encoding, &c->data.html.parser_binding); + if (err == BINDING_BADENCODING) { + /* Ok, we don't support the declared encoding. Bailing out + * isn't exactly user-friendly, so fall back to Windows-1252 */ + talloc_free(c->data.html.encoding); + c->data.html.encoding = talloc_strdup(c, "Windows-1252"); + if (c->data.html.encoding == NULL) { + union content_msg_data msg_data; + + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } + + err = binding_create_tree(c, c->data.html.encoding, + &c->data.html.parser_binding); + } + if (err != BINDING_OK) { union content_msg_data msg_data; -- cgit v1.2.3