Explorar el Código

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

Tim Ledbetter hace 7 meses
padre
commit
9face18ab2

+ 11 - 0
Libraries/LibWeb/HTML/HTMLOListElement.cpp

@@ -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;
+}
+
 }

+ 3 - 2
Libraries/LibWeb/HTML/HTMLOListElement.h

@@ -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();
     }