LibWeb: Use parse_non_negative_integer for colspan and rowspan parsing

`DeprecatedString::to_int` calls `StringUtils::convert_to_int`
internally. However, the integer parsing is not done in an HTML
spec-compliant way. For example, `colspan="2;"` is valid according to
the spec. But, with the current implementation, we will fail to parse
"2;", and instead fall back to using 1 as the colspan value.

This patch changes the `HTMLTableCellElement::col_span` and
`HTMLTableCellElement::row_span` methods to use the
`Web::HTML::parse_non_negative_integer` function that will parse the
attribute value in an HTML spec-compliant way.
This commit is contained in:
Jonatan Klemets 2023-07-23 20:03:43 +03:00 committed by Sam Atkins
parent 9812031a02
commit 04bc9b14d0
Notes: sideshowbarker 2024-07-17 04:34:25 +09:00
5 changed files with 405 additions and 2 deletions

View file

@ -14,6 +14,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLTableCellElement.h>
#include <LibWeb/HTML/HTMLTableElement.h>
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
namespace Web::HTML {
@ -96,7 +97,7 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
unsigned int HTMLTableCellElement::col_span() const
{
return attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
return Web::HTML::parse_non_negative_integer(attribute(HTML::AttributeNames::colspan)).value_or(1);
}
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_col_span(unsigned int value)
@ -106,7 +107,7 @@ WebIDL::ExceptionOr<void> HTMLTableCellElement::set_col_span(unsigned int value)
unsigned int HTMLTableCellElement::row_span() const
{
return attribute(HTML::AttributeNames::rowspan).to_uint().value_or(1);
return Web::HTML::parse_non_negative_integer(attribute(HTML::AttributeNames::rowspan)).value_or(1);
}
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_row_span(unsigned int value)