mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +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:
parent
6bfc35b6a9
commit
6218f1a609
Notes:
github-actions[bot]
2024-11-29 12:39:58 +00:00
Author: https://github.com/tcl3
Commit: 6218f1a609
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2635
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 41 additions and 4 deletions
|
@ -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()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue