Truly independent web browser
LibWeb: Check all ancestors of an option for a disabled optgroup
Andreas Kling207088076089
diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Libraries/LibWeb/HTML/HTMLOptionElement.cppindex a48b8f4dde0..a8320631ecc 100644--- a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp@@ -198,9 +198,26 @@ void HTMLOptionElement::ask_for_a_reset()// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-disabledbool HTMLOptionElement::disabled() const{- // An option element is disabled if its disabled attribute is present or if it is a child of an optgroup element whose disabled attribute is present.- return has_attribute(AttributeNames::disabled)- || (parent() && is<HTMLOptGroupElement>(parent()) && static_cast<HTMLOptGroupElement const&>(*parent()).has_attribute(AttributeNames::disabled));+ // An option element option is disabled if the following steps return true:++ // 1. If option's disabled attribute is present, then return true.+ if (has_attribute(AttributeNames::disabled))+ return true;++ // 2. For each ancestor of option's ancestors in reverse tree order:+ for (auto const* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {+ // 1. If ancestor is a select, hr, datalist, or option element, then return false.+ if (is<HTMLSelectElement>(*ancestor) || is<HTMLHRElement>(*ancestor) || is<HTMLDataListElement>(*ancestor) || is<HTMLOptionElement>(*ancestor))+ return false;++ // 2. If ancestor is an optgroup element, then return true if ancestor's disabled attribute is present;+ // otherwise false.+ if (auto const* optgroup = as_if<HTMLOptGroupElement>(*ancestor))+ return optgroup->has_attribute(AttributeNames::disabled);+ }++ // 3. Return false.+ return false;}// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-formdiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/customizable-select/option-disabled-optgroup-wrapper.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/customizable-select/option-disabled-optgroup-wrapper.txtindex aed421546ea..4564037dcbd 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/customizable-select/option-disabled-optgroup-wrapper.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/customizable-select/option-disabled-optgroup-wrapper.txt@@ -2,7 +2,7 @@ Harness status: OKFound 3 tests-3 Fail-Fail :disabled matches option in wrapper inside disabled optgroup-Fail :disabled updates dynamically when optgroup disabled changes with wrapper-Fail selectedness setting algorithm skips wrapped options in disabled optgroup\ No newline at end of file+3 Pass+Pass :disabled matches option in wrapper inside disabled optgroup+Pass :disabled updates dynamically when optgroup disabled changes with wrapper+Pass selectedness setting algorithm skips wrapped options in disabled optgroup\ No newline at end of file