diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-02-20 12:50:34 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-02-20 12:50:34 +0000 |
commit | 1f859400d962270ba418530e3a147004b4545963 (patch) | |
tree | 48a05d744ce6c778b80d60e2012333fbb13317ee /render | |
parent | 8bebcb5ca9d2760ff410a4c415a4f599ba9128fc (diff) | |
download | netsurf-1f859400d962270ba418530e3a147004b4545963.tar.gz netsurf-1f859400d962270ba418530e3a147004b4545963.tar.bz2 |
If we have no document charset on completion of parse, retrieve it from the binding.
Make the binding return Windows-1252 if it has no idea (as this is what the parser will have defaulted to).
Fix form_new to not require a document charset to be present -- it may not be known at this point.
Fixup form document charsets post-parse, so that form submission works correctly.
svn path=/trunk/netsurf/; revision=6575
Diffstat (limited to 'render')
-rw-r--r-- | render/form.c | 9 | ||||
-rw-r--r-- | render/html.c | 26 | ||||
-rw-r--r-- | render/hubbub_binding.c | 5 |
3 files changed, 32 insertions, 8 deletions
diff --git a/render/form.c b/render/form.c index 096d5d3dd..c9f1abe24 100644 --- a/render/form.c +++ b/render/form.c @@ -50,7 +50,7 @@ static char *form_encode_item(const char *item, const char *charset, * \param target Target frame of form, or NULL for default * \param method method and enctype * \param charset acceptable encodings for form submission, or NULL - * \param doc_charset encoding of containing document + * \param doc_charset encoding of containing document, or NULL * \return a new structure, or NULL on memory exhaustion */ struct form *form_new(void *node, const char *action, const char *target, @@ -59,8 +59,6 @@ struct form *form_new(void *node, const char *action, const char *target, { struct form *form; - assert(doc_charset != NULL); - form = calloc(1, sizeof *form); if (!form) return NULL; @@ -88,8 +86,9 @@ struct form *form_new(void *node, const char *action, const char *target, return NULL; } - form->document_charset = strdup(doc_charset); - if (form->document_charset == NULL) { + form->document_charset = doc_charset != NULL ? strdup(doc_charset) + : NULL; + if (doc_charset && form->document_charset == NULL) { free(form->accept_charsets); free(form->target); free(form->action); diff --git a/render/html.c b/render/html.c index 91f55b145..6887bdc80 100644 --- a/render/html.c +++ b/render/html.c @@ -333,6 +333,19 @@ bool html_convert(struct content *c, int width, int height) return false; } + if (c->data.html.encoding == NULL) { + const char *encoding = binding_get_encoding( + c->data.html.parser_binding, + &c->data.html.encoding_source); + + c->data.html.encoding = talloc_strdup(c, encoding); + if (c->data.html.encoding == NULL) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } + } + /* locate html and head elements */ html = xmlDocGetRootElement(c->data.html.document); if (html == 0 || strcmp((const char *) html->name, "html") != 0) { @@ -369,11 +382,11 @@ bool html_convert(struct content *c, int width, int height) #ifdef WITH_HUBBUB /* Retrieve forms from parser */ c->data.html.forms = binding_get_forms(c->data.html.parser_binding); - /* Make all actions absolute */ for (f = c->data.html.forms; f != NULL; f = f->prev) { char *action; url_func_result res; + /* Make all actions absolute */ res = url_join(f->action, c->data.html.base_url, &action); if (res != URL_FUNC_OK) { msg_data.error = messages_get("NoMemory"); @@ -383,6 +396,17 @@ bool html_convert(struct content *c, int width, int height) free(f->action); f->action = action; + + /* Ensure each form has a document encoding */ + if (f->document_charset == NULL) { + f->document_charset = strdup(c->data.html.encoding); + if (f->document_charset == NULL) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, + msg_data); + return false; + } + } } #endif diff --git a/render/hubbub_binding.c b/render/hubbub_binding.c index 79a3dba0f..b674d011c 100644 --- a/render/hubbub_binding.c +++ b/render/hubbub_binding.c @@ -139,7 +139,8 @@ binding_error binding_create_tree(void *arena, const char *charset, void **ctx) c->parser = NULL; c->encoding = charset; - c->encoding_source = ENCODING_SOURCE_HEADER; + c->encoding_source = charset != NULL ? ENCODING_SOURCE_HEADER + : ENCODING_SOURCE_DETECTED; c->document = NULL; c->owns_doc = true; c->forms = NULL; @@ -232,7 +233,7 @@ const char *binding_get_encoding(void *ctx, binding_encoding_source *source) *source = c->encoding_source; - return c->encoding; + return c->encoding != NULL ? c->encoding : "Windows-1252"; } xmlDocPtr binding_get_document(void *ctx) |