mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-30 13:19:47 +00:00
LibWeb: Limit HTMLInputElement.size to allowed values
Attempting to set `HTMLInputElement.size` to 0 via IDL now throws an IndexSizeError DOMException. Attempting to set it to a value larger than 2147483647 results in it being set to the default value.
This commit is contained in:
committed by
Andreas Kling
parent
08812a1f88
commit
ae0c87c747
@@ -1861,19 +1861,23 @@ WebIDL::ExceptionOr<void> HTMLInputElement::set_min_length(WebIDL::Long value)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#the-size-attribute
|
||||
unsigned HTMLInputElement::size() const
|
||||
WebIDL::UnsignedLong HTMLInputElement::size() const
|
||||
{
|
||||
// The size attribute, if specified, must have a value that is a valid non-negative integer greater than zero.
|
||||
// The size IDL attribute is limited to only positive numbers and has a default value of 20.
|
||||
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.value() != 0)
|
||||
if (auto size = parse_non_negative_integer(*size_string); size.has_value() && *size != 0 && *size <= 2147483647)
|
||||
return *size;
|
||||
}
|
||||
return 20;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::set_size(unsigned value)
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::set_size(WebIDL::UnsignedLong value)
|
||||
{
|
||||
if (value == 0)
|
||||
return WebIDL::IndexSizeError::create(realm(), "Size must be greater than zero"_string);
|
||||
if (value > 2147483647)
|
||||
value = 20;
|
||||
return set_attribute(HTML::AttributeNames::size, String::number(value));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user