LibWeb: Use correct integer parsing rules in HTMLOListElement::start()

This commit is contained in:
Tim Ledbetter 2024-11-26 15:46:31 +00:00 committed by Andreas Kling
parent a61883ae88
commit 9face18ab2
Notes: github-actions[bot] 2024-11-26 18:51:13 +00:00
2 changed files with 14 additions and 2 deletions

View file

@ -7,6 +7,7 @@
#include <LibWeb/Bindings/HTMLOListElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/HTMLOListElement.h>
#include <LibWeb/HTML/Numbers.h>
namespace Web::HTML {
@ -25,4 +26,14 @@ void HTMLOListElement::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLOListElement);
}
// https://html.spec.whatwg.org/multipage/grouping-content.html#dom-ol-start
WebIDL::Long HTMLOListElement::start()
{
// The start IDL attribute must reflect the content attribute of the same name, with a default value of 1.
auto content_attribute_value = get_attribute(AttributeNames::start).value_or("1"_string);
if (auto maybe_number = HTML::parse_integer(content_attribute_value); maybe_number.has_value())
return *maybe_number;
return 1;
}
}

View file

@ -8,6 +8,7 @@
#include <LibWeb/ARIA/Roles.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/WebIDL/Types.h>
namespace Web::HTML {
@ -21,8 +22,8 @@ public:
// https://www.w3.org/TR/html-aria/#el-ol
virtual Optional<ARIA::Role> default_role() const override { return ARIA::Role::list; }
i32 start() { return get_attribute(AttributeNames::start).value_or("1"_string).to_number<i32>().value_or(1); }
void set_start(i32 start)
WebIDL::Long start();
void set_start(WebIDL::Long start)
{
set_attribute(AttributeNames::start, String::number(start)).release_value_but_fixme_should_propagate_errors();
}