mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Limit HTMLSelectElement.size to allowed values
This change ensures that the correct default value of 0 is used and that values greater than 2147483647 will fall back to the default value. It also splits the display size concept into a separate method, as this isn't supposed to be used when getting the IDL property.
This commit is contained in:
committed by
Andreas Kling
parent
6bfc35b6a9
commit
6218f1a609
@@ -77,7 +77,7 @@ void HTMLSelectElement::adjust_computed_style(CSS::StyleProperties& style)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-size
|
||||
WebIDL::UnsignedLong HTMLSelectElement::size() const
|
||||
u32 HTMLSelectElement::display_size() const
|
||||
{
|
||||
// The size IDL attribute must reflect the respective content attributes of the same name. The size IDL attribute has a default value of 0.
|
||||
if (auto size_string = get_attribute(HTML::AttributeNames::size); size_string.has_value()) {
|
||||
@@ -94,8 +94,22 @@ WebIDL::UnsignedLong HTMLSelectElement::size() const
|
||||
return 1;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-size
|
||||
WebIDL::UnsignedLong HTMLSelectElement::size() const
|
||||
{
|
||||
// The multiple, required, and size IDL attributes must reflect the respective content attributes of the same name. The size IDL attribute has a default value of 0.
|
||||
if (auto size_string = get_attribute(HTML::AttributeNames::size); size_string.has_value()) {
|
||||
if (auto size = parse_non_negative_integer(*size_string); size.has_value() && *size <= 2147483647)
|
||||
return *size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> HTMLSelectElement::set_size(WebIDL::UnsignedLong size)
|
||||
{
|
||||
if (size > 2147483647)
|
||||
size = 0;
|
||||
return set_attribute(HTML::AttributeNames::size, String::number(size));
|
||||
}
|
||||
|
||||
@@ -574,7 +588,7 @@ void HTMLSelectElement::update_selectedness()
|
||||
return;
|
||||
|
||||
// If element's multiple attribute is absent, and element's display size is 1,
|
||||
if (size() == 1) {
|
||||
if (display_size() == 1) {
|
||||
bool has_selected_elements = false;
|
||||
for (auto const& option_element : list_of_options()) {
|
||||
if (option_element->selected()) {
|
||||
|
||||
Reference in New Issue
Block a user