Author: jmb
Date: Fri Feb 20 06:50:34 2009
New Revision: 6575
URL:
http://source.netsurf-browser.org?rev=6575&view=rev
Log:
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.
Modified:
trunk/netsurf/render/form.c
trunk/netsurf/render/html.c
trunk/netsurf/render/hubbub_binding.c
Modified: trunk/netsurf/render/form.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/render/form.c?rev=6575&am...
==============================================================================
--- trunk/netsurf/render/form.c (original)
+++ trunk/netsurf/render/form.c Fri Feb 20 06:50:34 2009
@@ -50,7 +50,7 @@
* \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,
@@ -58,8 +58,6 @@
const char *doc_charset)
{
struct form *form;
-
- assert(doc_charset != NULL);
form = calloc(1, sizeof *form);
if (!form)
@@ -88,8 +86,9 @@
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);
Modified: trunk/netsurf/render/html.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/render/html.c?rev=6575&am...
==============================================================================
--- trunk/netsurf/render/html.c (original)
+++ trunk/netsurf/render/html.c Fri Feb 20 06:50:34 2009
@@ -333,6 +333,19 @@
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 @@
#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 @@
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
Modified: trunk/netsurf/render/hubbub_binding.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/render/hubbub_binding.c?r...
==============================================================================
--- trunk/netsurf/render/hubbub_binding.c (original)
+++ trunk/netsurf/render/hubbub_binding.c Fri Feb 20 06:50:34 2009
@@ -139,7 +139,8 @@
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 @@
*source = c->encoding_source;
- return c->encoding;
+ return c->encoding != NULL ? c->encoding : "Windows-1252";
}
xmlDocPtr binding_get_document(void *ctx)