LibWeb: Set textarea rows and cols default value if 0

The cols and rows attributes are limited to only positive numbers with
fallback. The cols IDL attribute's default value is 20. The rows IDL
attribute's default value is 2.

The default value was returned only for the negative number. I added an
additional check for the case when the attribute is 0 to match the
specification.
This commit is contained in:
Piotr 2024-10-29 14:35:54 +01:00 committed by Jelle Raaijmakers
parent 5723ed3443
commit 205155a7ab
Notes: github-actions[bot] 2024-10-29 22:38:06 +00:00

View file

@ -291,7 +291,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())
if (auto cols = parse_non_negative_integer(*cols_string); cols.has_value() && *cols > 0)
return *cols;
}
return 20;
@ -307,7 +307,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())
if (auto rows = parse_non_negative_integer(*rows_string); rows.has_value() && *rows > 0)
return *rows;
}
return 2;