diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
index 17da0fab735..25783590a01 100644
--- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
@@ -293,7 +293,7 @@ unsigned HTMLTextAreaElement::cols() const
{
// The cols and rows attributes are limited to only positive numbers with fallback. The cols IDL attribute's default value is 20.
if (auto cols_string = get_attribute(HTML::AttributeNames::cols); cols_string.has_value()) {
- if (auto cols = parse_non_negative_integer(*cols_string); cols.has_value() && *cols > 0)
+ if (auto cols = parse_non_negative_integer(*cols_string); cols.has_value() && *cols > 0 && *cols <= 2147483647)
return *cols;
}
return 20;
@@ -301,6 +301,9 @@ unsigned HTMLTextAreaElement::cols() const
WebIDL::ExceptionOr HTMLTextAreaElement::set_cols(unsigned cols)
{
+ if (cols > 2147483647)
+ cols = 20;
+
return set_attribute(HTML::AttributeNames::cols, String::number(cols));
}
@@ -309,7 +312,7 @@ unsigned HTMLTextAreaElement::rows() const
{
// The cols and rows attributes are limited to only positive numbers with fallback. The rows IDL attribute's default value is 2.
if (auto rows_string = get_attribute(HTML::AttributeNames::rows); rows_string.has_value()) {
- if (auto rows = parse_non_negative_integer(*rows_string); rows.has_value() && *rows > 0)
+ if (auto rows = parse_non_negative_integer(*rows_string); rows.has_value() && *rows > 0 && *rows <= 2147483647)
return *rows;
}
return 2;
@@ -317,6 +320,9 @@ unsigned HTMLTextAreaElement::rows() const
WebIDL::ExceptionOr HTMLTextAreaElement::set_rows(unsigned rows)
{
+ if (rows > 2147483647)
+ rows = 2;
+
return set_attribute(HTML::AttributeNames::rows, String::number(rows));
}
diff --git a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt
index 565a060efba..154bf557425 100644
--- a/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt
+++ b/Tests/LibWeb/Text/expected/HTML/unsigned-long-reflection.txt
@@ -46,3 +46,35 @@ marquee.getAttribute("scrolldelay") after marquee.setAttribute("scrollDelay", "4
marquee.scrollDelay after marquee.setAttribute("scrolldelay", "4294967295"): 85
marquee.getAttribute("scrolldelay") after marquee.scrollDelay = 4294967295: 85
marquee.scrollDelay after marquee.scrollDelay = 4294967295: 85
+textarea.getAttribute("rows") after textarea.setAttribute("rows", "1"): 1
+textarea.rows after textarea.setAttribute("rows", "1"): 1
+textarea.getAttribute("rows") after textarea.rows = 1: 1
+textarea.rows after textarea.rows = 1: 1
+textarea.getAttribute("rows") after textarea.setAttribute("rows", "2147483647"): 2147483647
+textarea.rows after textarea.setAttribute("rows", "2147483647"): 2147483647
+textarea.getAttribute("rows") after textarea.rows = 2147483647: 2147483647
+textarea.rows after textarea.rows = 2147483647: 2147483647
+textarea.getAttribute("rows") after textarea.setAttribute("rows", "2147483648"): 2147483648
+textarea.rows after textarea.setAttribute("rows", "2147483648"): 2
+textarea.getAttribute("rows") after textarea.rows = 2147483648: 2
+textarea.rows after textarea.rows = 2147483648: 2
+textarea.getAttribute("rows") after textarea.setAttribute("rows", "4294967295"): 4294967295
+textarea.rows after textarea.setAttribute("rows", "4294967295"): 2
+textarea.getAttribute("rows") after textarea.rows = 4294967295: 2
+textarea.rows after textarea.rows = 4294967295: 2
+textarea.getAttribute("cols") after textarea.setAttribute("cols", "1"): 1
+textarea.cols after textarea.setAttribute("cols", "1"): 1
+textarea.getAttribute("cols") after textarea.cols = 1: 1
+textarea.cols after textarea.cols = 1: 1
+textarea.getAttribute("cols") after textarea.setAttribute("cols", "2147483647"): 2147483647
+textarea.cols after textarea.setAttribute("cols", "2147483647"): 2147483647
+textarea.getAttribute("cols") after textarea.cols = 2147483647: 2147483647
+textarea.cols after textarea.cols = 2147483647: 2147483647
+textarea.getAttribute("cols") after textarea.setAttribute("cols", "2147483648"): 2147483648
+textarea.cols after textarea.setAttribute("cols", "2147483648"): 20
+textarea.getAttribute("cols") after textarea.cols = 2147483648: 20
+textarea.cols after textarea.cols = 2147483648: 20
+textarea.getAttribute("cols") after textarea.setAttribute("cols", "4294967295"): 4294967295
+textarea.cols after textarea.setAttribute("cols", "4294967295"): 20
+textarea.getAttribute("cols") after textarea.cols = 4294967295: 20
+textarea.cols after textarea.cols = 4294967295: 20
diff --git a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html
index d951a6754d1..f9c7d2e759e 100644
--- a/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html
+++ b/Tests/LibWeb/Text/input/HTML/unsigned-long-reflection.html
@@ -25,5 +25,7 @@
testProperty("img", "hspace", (img) => img.hspace, (img, value) => img.hspace = value);
testProperty("marquee", "scrollAmount", (marquee) => marquee.scrollAmount, (marquee, value) => marquee.scrollAmount = value);
testProperty("marquee", "scrollDelay", (marquee) => marquee.scrollDelay, (marquee, value) => marquee.scrollDelay = value);
+ testProperty("textarea", "rows", (textarea) => textarea.rows, (textarea, value) => textarea.rows = value);
+ testProperty("textarea", "cols", (textarea) => textarea.cols, (textarea, value) => textarea.cols = value);
});