check dom call return and improve handling of missing form type

This commit is contained in:
Vincent Sanders 2018-10-09 17:00:22 +01:00
parent 8687265c9a
commit e275b3175b

View File

@ -2476,49 +2476,57 @@ static bool box_input_text(html_content *html, struct box *box,
bool box_input(BOX_SPECIAL_PARAMS) bool box_input(BOX_SPECIAL_PARAMS)
{ {
struct form_control *gadget = NULL; struct form_control *gadget;
dom_string *type = NULL; dom_string *type = NULL;
dom_exception err; dom_exception err;
nsurl *url; nsurl *url;
nserror error; nserror error;
dom_element_get_attribute(n, corestring_dom_type, &type);
gadget = html_forms_get_control_for_node(content->forms, n); gadget = html_forms_get_control_for_node(content->forms, n);
if (gadget == NULL) if (gadget == NULL) {
goto no_memory; return false;
}
box->gadget = gadget; box->gadget = gadget;
box->flags |= IS_REPLACED; box->flags |= IS_REPLACED;
gadget->box = box; gadget->box = box;
gadget->html = content; gadget->html = content;
if (type && dom_string_caseless_lwc_isequal(type, /* get entry type */
corestring_lwc_password)) { err = dom_element_get_attribute(n, corestring_dom_type, &type);
if ((err != DOM_NO_ERR) || (type == NULL)) {
/* no type so "text" is assumed */
if (box_input_text(content, box, n) == false) {
return false;
}
*convert_children = false;
return true;
}
if (dom_string_caseless_lwc_isequal(type, corestring_lwc_password)) {
if (box_input_text(content, box, n) == false) if (box_input_text(content, box, n) == false)
goto no_memory; goto no_memory;
} else if (type && dom_string_caseless_lwc_isequal(type, } else if (dom_string_caseless_lwc_isequal(type, corestring_lwc_file)) {
corestring_lwc_file)) {
box->type = BOX_INLINE_BLOCK; box->type = BOX_INLINE_BLOCK;
} else if (type && dom_string_caseless_lwc_isequal(type, } else if (dom_string_caseless_lwc_isequal(type,
corestring_lwc_hidden)) { corestring_lwc_hidden)) {
/* no box for hidden inputs */ /* no box for hidden inputs */
box->type = BOX_NONE; box->type = BOX_NONE;
} else if (type && } else if ((dom_string_caseless_lwc_isequal(type,
(dom_string_caseless_lwc_isequal(type,
corestring_lwc_checkbox) || corestring_lwc_checkbox) ||
dom_string_caseless_lwc_isequal(type, dom_string_caseless_lwc_isequal(type,
corestring_lwc_radio))) { corestring_lwc_radio))) {
} else if (type && } else if (dom_string_caseless_lwc_isequal(type,
(dom_string_caseless_lwc_isequal(type,
corestring_lwc_submit) || corestring_lwc_submit) ||
dom_string_caseless_lwc_isequal(type, dom_string_caseless_lwc_isequal(type,
corestring_lwc_reset) || corestring_lwc_reset) ||
dom_string_caseless_lwc_isequal(type, dom_string_caseless_lwc_isequal(type,
corestring_lwc_button))) { corestring_lwc_button)) {
struct box *inline_container, *inline_box; struct box *inline_container, *inline_box;
if (box_button(n, content, box, 0) == false) if (box_button(n, content, box, 0) == false)
@ -2560,11 +2568,12 @@ bool box_input(BOX_SPECIAL_PARAMS)
box_add_child(box, inline_container); box_add_child(box, inline_container);
} else if (type && dom_string_caseless_lwc_isequal(type, } else if (dom_string_caseless_lwc_isequal(type,
corestring_lwc_image)) { corestring_lwc_image)) {
gadget->type = GADGET_IMAGE; gadget->type = GADGET_IMAGE;
if (box->style && ns_computed_display(box->style, if (box->style &&
ns_computed_display(box->style,
box_is_root(n)) != CSS_DISPLAY_NONE && box_is_root(n)) != CSS_DISPLAY_NONE &&
nsoption_bool(foreground_images) == true) { nsoption_bool(foreground_images) == true) {
dom_string *s; dom_string *s;
@ -2595,19 +2604,18 @@ bool box_input(BOX_SPECIAL_PARAMS)
} }
} }
} else { } else {
/* the default type is "text" */ /* unhandled type the default is "text" */
if (box_input_text(content, box, n) == false) if (box_input_text(content, box, n) == false)
goto no_memory; goto no_memory;
} }
if (type)
dom_string_unref(type); dom_string_unref(type);
*convert_children = false; *convert_children = false;
return true; return true;
no_memory: no_memory:
if (type)
dom_string_unref(type); dom_string_unref(type);
return false; return false;