Skip to content

Commit

Permalink
LibWeb: Use correct integer parsing rules in HTMLOListElement::start()
Browse files Browse the repository at this point in the history
(cherry picked from commit 9face18ab265376916aa18c0adce113596b99a1e)
  • Loading branch information
tcl3 authored and nico committed Nov 26, 2024
1 parent 5ea38ea commit 69db9bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLOListElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}

}
5 changes: 3 additions & 2 deletions Userland/Libraries/LibWeb/HTML/HTMLOListElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <LibWeb/ARIA/Roles.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/WebIDL/Types.h>

namespace Web::HTML {

Expand All @@ -21,8 +22,8 @@ class HTMLOListElement final : public HTMLElement {
// 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, MUST(String::number(start))).release_value_but_fixme_should_propagate_errors();
}
Expand Down

0 comments on commit 69db9bd

Please sign in to comment.