diff --git a/Libraries/LibWeb/HTML/HTMLTableColElement.cpp b/Libraries/LibWeb/HTML/HTMLTableColElement.cpp
index 753a76b5013..48351f6b6ee 100644
--- a/Libraries/LibWeb/HTML/HTMLTableColElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLTableColElement.cpp
@@ -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(*span_digits);
+ // NOTE: If span has no value at this point, the value must be larger than NumericLimits::max(), so return the maximum value of 1000.
+ if (!span.has_value())
+ return 1000;
return clamp(*span, 1, 1000);
+ }
}
return 1;
}
WebIDL::ExceptionOr HTMLTableColElement::set_span(unsigned int value)
{
+ if (value > 2147483647)
+ value = 1;
return set_attribute(HTML::AttributeNames::span, String::number(value));
}
diff --git a/Libraries/LibWeb/HTML/HTMLTableColElement.h b/Libraries/LibWeb/HTML/HTMLTableColElement.h
index 9da04faeb45..a5d499199f9 100644
--- a/Libraries/LibWeb/HTML/HTMLTableColElement.h
+++ b/Libraries/LibWeb/HTML/HTMLTableColElement.h
@@ -7,6 +7,7 @@
#pragma once
#include
+#include
namespace Web::HTML {
@@ -17,8 +18,8 @@ class HTMLTableColElement final : public HTMLElement {
public:
virtual ~HTMLTableColElement() override;
- unsigned span() const;
- WebIDL::ExceptionOr set_span(unsigned);
+ WebIDL::UnsignedLong span() const;
+ WebIDL::ExceptionOr set_span(WebIDL::UnsignedLong);
private:
HTMLTableColElement(DOM::Document&, DOM::QualifiedName);
diff --git a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt
index cb4ba245cff..661c8c059bc 100644
--- a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt
+++ b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt
@@ -46,6 +46,30 @@ canvas.getAttribute("height") after canvas.setAttribute("height", "4294967296"):
canvas.height after canvas.setAttribute("height", "4294967296"): 150
canvas.getAttribute("height") after canvas.height = 4294967296: 0
canvas.height after canvas.height = 4294967296: 0
+colgroup.getAttribute("span") after colgroup.setAttribute("span", "0"): 0
+colgroup.span after colgroup.setAttribute("span", "0"): 1
+colgroup.getAttribute("span") after colgroup.span = 0: 0
+colgroup.span after colgroup.span = 0: 1
+colgroup.getAttribute("span") after colgroup.setAttribute("span", "1"): 1
+colgroup.span after colgroup.setAttribute("span", "1"): 1
+colgroup.getAttribute("span") after colgroup.span = 1: 1
+colgroup.span after colgroup.span = 1: 1
+colgroup.getAttribute("span") after colgroup.setAttribute("span", "2147483647"): 2147483647
+colgroup.span after colgroup.setAttribute("span", "2147483647"): 1000
+colgroup.getAttribute("span") after colgroup.span = 2147483647: 2147483647
+colgroup.span after colgroup.span = 2147483647: 1000
+colgroup.getAttribute("span") after colgroup.setAttribute("span", "2147483648"): 2147483648
+colgroup.span after colgroup.setAttribute("span", "2147483648"): 1000
+colgroup.getAttribute("span") after colgroup.span = 2147483648: 1
+colgroup.span after colgroup.span = 2147483648: 1
+colgroup.getAttribute("span") after colgroup.setAttribute("span", "4294967295"): 4294967295
+colgroup.span after colgroup.setAttribute("span", "4294967295"): 1000
+colgroup.getAttribute("span") after colgroup.span = 4294967295: 1
+colgroup.span after colgroup.span = 4294967295: 1
+colgroup.getAttribute("span") after colgroup.setAttribute("span", "4294967296"): 4294967296
+colgroup.span after colgroup.setAttribute("span", "4294967296"): 1000
+colgroup.getAttribute("span") after colgroup.span = 4294967296: 0
+colgroup.span after colgroup.span = 4294967296: 1
img.getAttribute("height") after img.setAttribute("height", "0"): 0
img.height after img.setAttribute("height", "0"): 0
img.getAttribute("height") after img.height = 0: 0
diff --git a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html
index 8a596d9d0a8..d1ffbaec207 100644
--- a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html
+++ b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html
@@ -45,6 +45,7 @@
testProperty("canvas", "width", (canvas) => canvas.width, (canvas, value) => canvas.width = value);
testProperty("canvas", "height", (canvas) => canvas.height, (canvas, value) => canvas.height = value);
+ testProperty("colgroup", "span", (colgroup) => colgroup.span, (colgroup, value) => colgroup.span = value);
testProperty("img", "height", (img) => img.height, (img, value) => img.height = value);
testProperty("img", "hspace", (img) => img.hspace, (img, value) => img.hspace = value);
testProperty("img", "width", (img) => img.width, (img, value) => img.width = value);