From 91b29b626f54bd76710a74c400c2a6c0bdb6a4be Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sun, 25 Feb 2024 14:57:58 +0000 Subject: [PATCH] HTML/forms: fix radio button group handling --- content/handlers/html/form.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c index 8c8120877..9b6768a56 100644 --- a/content/handlers/html/form.c +++ b/content/handlers/html/form.c @@ -2002,20 +2002,33 @@ void form_radio_set(struct form_control *radio) if (radio->selected) return; + /* Clear selected state for other controls in + * the same radio button group */ for (control = radio->form->controls; control != NULL; control = control->next) { + /* Only interested in radio inputs */ if (control->type != GADGET_RADIO) continue; + /* Ignore ourself */ if (control == radio) continue; - if ((control->name != NULL) && - (radio->name != NULL) && + /* Ignore inputs where: + * a) this or the other control have no name attribute + * b) this or the other control have an empty name attribute + * c) the control names do not match + */ + if ((control->name == NULL) || + (radio->name == NULL) || + (control->name[0] == '\0') || + (radio->name[0] == '\0') || strcmp(control->name, radio->name) != 0) continue; + /* Other control is in the same radio button group: clear its + * selected state */ if (control->selected) { control->selected = false; dom_html_input_element_set_checked(control->node, false);