mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +00:00
LibWeb: Limit HTMLTableColElement
span to allowed values
This change ensures that `span` is clamped to the maximum value of 1000 if the given value is larger than 2147483647.
This commit is contained in:
parent
9fc2a63131
commit
44cf457fd2
Notes:
github-actions[bot]
2024-12-02 09:26:24 +00:00
Author: https://github.com/tcl3
Commit: 44cf457fd2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2685
4 changed files with 37 additions and 4 deletions
|
@ -29,18 +29,25 @@ void HTMLTableColElement::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/tables.html#dom-colgroup-span
|
||||
unsigned int HTMLTableColElement::span() const
|
||||
WebIDL::UnsignedLong HTMLTableColElement::span() const
|
||||
{
|
||||
// The span IDL attribute must reflect the content attribute of the same name. It is clamped to the range [1, 1000], and its default value is 1.
|
||||
if (auto span_string = get_attribute(HTML::AttributeNames::span); span_string.has_value()) {
|
||||
if (auto span = parse_non_negative_integer(*span_string); span.has_value())
|
||||
if (auto span_digits = parse_non_negative_integer_digits(*span_string); span_digits.has_value()) {
|
||||
auto span = AK::StringUtils::convert_to_int<i64>(*span_digits);
|
||||
// NOTE: If span has no value at this point, the value must be larger than NumericLimits<i64>::max(), so return the maximum value of 1000.
|
||||
if (!span.has_value())
|
||||
return 1000;
|
||||
return clamp(*span, 1, 1000);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
|
||||
{
|
||||
if (value > 2147483647)
|
||||
value = 1;
|
||||
return set_attribute(HTML::AttributeNames::span, String::number(value));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue